From 420c6ed83bdead648faae44ba3ed2743a8751b8a Mon Sep 17 00:00:00 2001 From: devome Date: Fri, 21 Oct 2022 14:03:40 +0800 Subject: [PATCH] =?UTF-8?q?docker=E4=BB=A5=E6=99=AE=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=BF=90=E8=A1=8Cjava=E5=92=8Cnginx=EF=BC=8C=E9=99=8D?= =?UTF-8?q?=E4=BD=8E=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 25 ++++++++++++++----------- README.md | 4 ++++ README_EN.md | 11 ++++++++++- entrypoint.sh | 6 +++++- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2fa11305..70bcc737 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,30 @@ FROM alpine:3.16 ENV LANG=zh_CN.UTF-8 \ TZ=Asia/Shanghai \ + PUID=1000 \ + PGID=1000 \ PS1="\u@\h:\w \$ " -RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ - && apk add --update --no-cache \ +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.bfsu.edu.cn/g' /etc/apk/repositories \ + && apk add --no-cache \ + acme.sh \ + curl \ + fontconfig \ + net-tools \ nginx \ nginx-mod-stream \ nginx-mod-http-headers-more \ openjdk8-jre \ - net-tools \ - curl \ - wget \ + shadow \ + su-exec \ + tini \ ttf-dejavu \ - fontconfig \ tzdata \ - tini \ - acme.sh \ + wget \ && fc-cache -f -v \ && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \ && echo "${TZ}" > /etc/timezone \ && rm -rf /var/cache/apk/* /tmp/* COPY target/nginxWebUI-*.jar /home/nginxWebUI.jar -COPY entrypoint.sh /usr/local/bin/entrypoint.sh -RUN ["chmod", "+x", "/usr/local/bin/entrypoint.sh"] +COPY --chmod=755 entrypoint.sh /usr/local/bin/entrypoint.sh VOLUME ["/home/nginxWebUI"] -ENTRYPOINT ["tini", "entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["tini", "entrypoint.sh"] diff --git a/README.md b/README.md index bc4151d0..ae8aab89 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,8 @@ docker pull cym1102/nginxwebui:latest docker run -itd \ -v /home/nginxWebUI:/home/nginxWebUI \ -e BOOT_OPTIONS="--server.port=8080" \ + -e PUID=1000 `# 以什么用户运行nginxwebui,该用户的uid` \ + -e PGID=1000 `# 以什么用户运行nginxwebui,该用户的gid` \ --privileged=true \ --net=host \ cym1102/nginxwebui:latest @@ -173,6 +175,8 @@ services: target: "/home/nginxWebUI" environment: BOOT_OPTIONS: "--server.port=8080" + PUID: "1000" # 以什么用户运行nginxwebui,该用户的uid + PGID: "1000" # 以什么用户运行nginxwebui,该用户的gid privileged: true network_mode: "host" diff --git a/README_EN.md b/README_EN.md index 2625e84e..78cc558c 100644 --- a/README_EN.md +++ b/README_EN.md @@ -132,7 +132,14 @@ docker pull cym1102/nginxwebui:latest 3.start container ``` -docker run -itd -v /home/nginxWebUI:/home/nginxWebUI -e BOOT_OPTIONS="--server.port=8080" --privileged=true --net=host cym1102/nginxwebui:latest +docker run -itd \ + -v /home/nginxWebUI:/home/nginxWebUI \ + -e BOOT_OPTIONS="--server.port=8080" \ + -e PUID=1000 `# user's uid` \ + -e PGID=1000 `# user's gid` \ + --privileged=true \ + --net=host \ + cym1102/nginxwebui:latest ``` notice: @@ -160,6 +167,8 @@ services: target: "/home/nginxWebUI" environment: BOOT_OPTIONS: "--server.port=8080" + PUID: "1000" # user's uid + PGID: "1000" # user's gid privileged: true network_mode: "host" diff --git a/entrypoint.sh b/entrypoint.sh index 7a7367c6..ef3de385 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,8 @@ #!/bin/sh +groupmod -o -g "${PGID}" nginx +usermod -o -u "${PUID}" nginx +chown -R ${PUID}:${PGID} /home/nginxWebUI.jar /home/nginxWebUI /var/lib/nginx /var/log/nginx /run/nginx + cd /home -exec java -jar -Dfile.encoding=UTF-8 -Xmx64m nginxWebUI.jar ${BOOT_OPTIONS} > /dev/null +exec su-exec ${PUID}:${PGID} java -jar -Dfile.encoding=UTF-8 -Xmx64m nginxWebUI.jar ${BOOT_OPTIONS} >/dev/null -- Gitee