diff --git a/Dockerfile b/Dockerfile index f089584..ed3bfdf 100755 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,6 @@ RUN pyinstaller --onefile --noconfirm --clean ./.build/ddns.spec FROM alpine:latest LABEL maintainer="NN708" +COPY --from=0 /app/entrypoint.sh / COPY --from=0 /app/dist/ddns / -RUN echo "*/5 * * * * /ddns -c /config.json" > /etc/crontabs/root -CMD [ "crond", "-f" ] +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/README.md b/README.md index 09b97fc..1d5bc87 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,24 @@ 1. clone 或者[下载此仓库](https://github.com/NewFuture/DDNS/archive/master.zip)并解压 2. 运行./run.py (widnows 双击`run.bat`或者运行`python run.py`) - #### Docker(需要安装 Docker) - `docker run -d -v /path/to/config.json:/config.json --network host newfuture/ddns` + - 使用环境变量: + ``` + docker run -d \ + -e DDNS_DNS=dnspod \ + -e DDNS_ID=12345 \ + -e DDNS_TOKEN=mytokenkey \ + -e DDNS_IPV4=ddns.newfuture.cc \ + -e DDNS_IPV6=ddns.newfuture.cc \ + --network host \ + newfuture/ddns + ``` + - 使用配置文件: + ``` + docker run -d \ + -v /path/to/config.json:/config.json \ + --network host \ + newfuture/ddns + ``` ### ② 快速配置 @@ -186,12 +203,12 @@ python run.py -c /path/to/config.json 可以通过脚本设置定时任务(默认每5分钟检查一次ip,自动更新) -#### windows +#### Windows - [推荐]以系统身份运行,右键"以管理员身份运行"`task.bat`(或者在管理员命令行中运行) - 以当前用户身份运行定时任务,双击或者运行`task.bat` (执行时会闪黑框) -#### linux +#### Linux - 使用init.d和crontab: `sudo ./task.sh` @@ -205,6 +222,10 @@ python run.py -c /path/to/config.json 该脚本安装的文件符合 [Filesystem Hierarchy Standard (FHS)](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard): 可执行文件所在目录为 `/usr/share/DDNS` 配置文件所在目录为 `/etc/DDNS` + +#### Docker + +Docker镜像在无额外参数的情况下,已默认启用每5分钟执行一次的定时任务 ## FAQ diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..c697c6b --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +if [ $# -eq 0 ]; then + printenv > /etc/environment + echo "*/5 * * * * /ddns -c /config.json" > /etc/crontabs/root + exec crond -f +else + first=`echo $1 | cut -c1` + if [ "$first" = "-" ]; then + exec /ddns $@ + else + exec $@ + fi +fi