diff --git a/Dockerfile b/Dockerfile index 48eb823..5a25ffa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,5 +7,11 @@ WORKDIR /bing COPY requirements.txt requirements.txt RUN pip3 install -r requirements.txt COPY src/ . +COPY entrypoint.sh . +RUN chmod +x entrypoint.sh -CMD [ "python3", "app.py", "--service-mode"] +RUN apt-get update && apt-get install -y \ + gosu \ + && rm -rf /var/lib/apt/lists/* + +ENTRYPOINT ["/bing/entrypoint.sh", "python3", "app.py", "--service-mode"] diff --git a/README.md b/README.md index e1e7ac3..a76a037 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,10 @@ All args can be read from environment variables, the environment variables with ## Docker Usage -Run as service and periodically scan new wallpaper: +Run as service and periodically scan new wallpaper. + + +Note that bing-dl runs as UID 1000 and GID 1000 by default. These may be altered with the `PUID` and `PGID` environment variables. ```shell docker run -d \ @@ -69,6 +72,8 @@ docker run -d \ -e BING_NOTIFY_MAIL=example@qq.com \ -e BING_NOTIFY_USER_MAIL=example@163.com \ -e BING_NOTIFY_USER_PASS=password \ + -e PUID=1000 \ + -e PGID=1000 \ -v /path/to/storage/folder:/bing/storage \ -v /path/to/download/folder:/bing/download \ littleneko/bing-dl:latest diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..7de5f51 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,16 @@ +#! /bin/sh + +set -eu + +PUID=${PUID:-1000} +PGID=${PGID:-1000} + +if ! getent group "$PGID" >/dev/null; then + groupadd -g "$PGID" bing +fi + +if ! getent passwd "$PUID" >/dev/null; then + useradd -u "$PUID" -g "$PGID" -m bing +fi + +exec gosu "$PUID":"$PGID" "$@"