diff --git a/1.16.1/.dockerignore b/1.16.1/.dockerignore deleted file mode 100644 index b3e8a3d..0000000 --- a/1.16.1/.dockerignore +++ /dev/null @@ -1,4 +0,0 @@ -.git -.gitignore -README.md -LICENSE \ No newline at end of file diff --git a/1.16.1/README.md b/1.16.1/README.md deleted file mode 100644 index 78d1cc7..0000000 --- a/1.16.1/README.md +++ /dev/null @@ -1,118 +0,0 @@ -# Nginx Ubuntu - -基于的 Ubuntu(18.04) 系统的 Nginx 镜像,用于提供 WEB(nginx) 服务。 - - - -## 基本信息 - -* 镜像地址:endial/nginx:1.16.1 - * 依赖镜像:endial/ubuntu:18.04 - - - -## 数据卷 - -镜像默认提供以下数据卷定义: - -```shell - /srv/www # 站点源文件 - /srv/conf # nginx 配置文件,配置文件存放在 nginx 子目录中 - /var/log # 日志文件,nginx 日志存放在子目录 nginx 中 - /var/run # 进程运行PID文件 -``` - -如果需要持久化存储相应数据,需要在宿主机建立本地目录,并在使用镜像初始化容器时进行映射。 - -举例: - -- 使用宿主机`/opt/conf`存储配置文件 -- 使用宿主机`/srv/data`存储数据文件 -- 使用宿主机`/srv/log`存储日志文件 - -创建以上相应的宿主机目录后,容器启动命令中对应的映射参数类似如下: - -```dockerfile --v /host/dir/to/conf:/srv/conf -v /host/dir/to/data:/srv/data -v /host/dir/to/log:/var/log -``` - -> 注意:应用需要使用的子目录会自动创建。 - - - -## 使用说明 - - - -### 运行容器 - -生成并运行一个新的容器: - -```bash -docker run -d --name nginx \ - -p 80:8080 \ - -v /host/dir/to/www:/srv/www:ro \ - -v /host/dir/to/log:/var/log \ - -v /host/dir/to/conf:/srv/conf \ - endial/nginx:1.16.1 -``` - -使用宿主机用户(如`www-data`用户)生成新的容器: - -```shell -docker run -d --name nginx \ - --user www-data \ - -p 80:8080 \ - -v /host/dir/to/www:/srv/www:ro \ - -v /host/dir/to/log:/var/log \ - -v /host/dir/to/conf:/srv/conf \ - endial/nginx:1.16.1 -``` - -> 注意:如果使用自定义用户创建容器,且需要使用数据卷,可以有两种方式确保权限正确: -> -> - 指定数据卷目录中不存在nginx子目录,由容器创建对应nginx目录及配置文件,然后个性化修改 -> - 指定数据卷目录中存在nginx子目录,需要确保子目录及目录中文件属于启动容器时所指定的用户组 - -如果存在`dvc`数据容器,可以使用以下命令: - -```bash -docker run -d --name nginx \ - -p 80:8080 \ - --volumes-from dvc \ - endial/nginx:1.16.1 -``` - - - -### 进入容器 - -使用容器ID或启动时的命名(本例中命名为`php-fpm`)进入容器: - -```shell -docker exec -it nginx /bin/bash -``` - - - -### 停止容器 - -使用容器ID或启动时的命名(本例中命名为`php-fpm`)停止: - -```shell -docker stop nginx -``` - - - -## 注意事项 - -- 容器中启动参数不能配置为后台运行,只能使用前台运行方式,即:`daemonize no` -- 如果应用使用后台方式运行,则容器的启动命令会在运行后自动退出,从而导致容器退出 - - - ----- - -本文原始来源 [Endial Fang](https://github.com/endial) @ [Github.com](https://github.com) - diff --git a/.dockerignore b/1.16/.dockerignore similarity index 100% rename from .dockerignore rename to 1.16/.dockerignore diff --git a/1.16.1/Dockerfile b/1.16/Dockerfile similarity index 75% rename from 1.16.1/Dockerfile rename to 1.16/Dockerfile index e92da6b..3227c46 100644 --- a/1.16.1/Dockerfile +++ b/1.16/Dockerfile @@ -1,15 +1,15 @@ -FROM endial/ubuntu:18.04 +FROM colovu/ubuntu:18.04 ENV APP_MAJOR=1.16.1 \ PCRE_VERSION=8.43 \ OPENSSL_VERSION=1.1.1e \ - HTTP_FLV_VERSION=1.2.7 -# APP_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 + HTTP_FLV_VERSION=1.2.7 \ + NGINX_KEYS='0xB0F4253373F8F6F510D42178520A9993A1C052F8' LABEL \ "Version"="v${APP_MAJOR}" \ "Description"="Docker image for Nginx ${APP_MAJOR} based on Ubuntu 18.04." \ - "Dockerfile"="https://github.com/endial/docker-nginx" \ + "Dockerfile"="https://github.com/colovu/docker-nginx" \ "Vendor"="Endial Fang (endial@126.com)" RUN set -eux; \ @@ -63,6 +63,8 @@ RUN set -eux; \ --with-poll_module \ --with-mail \ "; \ + \ +# 更新源,并安装临时使用的软件包(使用完后可删除) fetchDeps=" \ autoconf \ automake \ @@ -83,9 +85,11 @@ RUN set -eux; \ libgeoip-dev \ libterm-readkey-perl \ "; \ + savedAptMark="$(apt-mark showmanual)"; \ apt-get update; \ apt-get install -y ${fetchDeps}; \ \ +# 安装应用程序及需要依赖的软件包 apt install -y --no-install-recommends \ zlib1g \ libxml2 \ @@ -98,7 +102,6 @@ RUN set -eux; \ \ wget -O nginx.tar.gz "http://nginx.org/download/nginx-${APP_MAJOR}.tar.gz"; \ wget -O nginx.tar.gz.asc "http://nginx.org/download/nginx-${APP_MAJOR}.tar.gz.asc"; \ -# wget -O nginx_signing.key "https://nginx.org/keys/nginx_signing.key"; \ \ wget -O openssl.tar.gz --no-check-certificate "https://www.openssl.org/source/old/1.1.1/openssl-${OPENSSL_VERSION}.tar.gz"; \ wget -O openssl.tar.gz.asc --no-check-certificate "https://www.openssl.org/source/old/1.1.1/openssl-${OPENSSL_VERSION}.tar.gz.asc"; \ @@ -108,14 +111,18 @@ RUN set -eux; \ \ wget -O nginx-http-flv.tar.gz --no-check-certificate "https://github.com/winshining/nginx-http-flv-module/archive/v${HTTP_FLV_VERSION}.tar.gz"; \ \ -# verify the signature -# export GNUPGHOME="$(mktemp -d)"; \ -## gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys ${APP_KEYS}; \ -# gpg --import nginx_signing.key; \ -# gpg --batch --verify nginx.tar.gz.asc nginx.tar.gz; \ -# command -v gpgconf > /dev/null && gpgconf --kill all || :; \ -# rm -r "$GNUPGHOME" nginx.tar.gz.asc; \ -# apt-key list; \ +# 安装软件包需要使用的GPG证书 + export GNUPGHOME="$(mktemp -d)"; \ + for key in ${NGINX_KEYS}; do \ + gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "${key}"|| \ + gpg --batch --keyserver pgp.mit.edu --recv-keys "${key}" || \ + gpg --batch --keyserver keys.gnupg.net --recv-keys "${key}" || \ + gpg --batch --keyserver keyserver.pgp.com --recv-keys "${key}"; \ + done; \ + gpg --batch --verify nginx.tar.gz.asc nginx.tar.gz; \ + \ + command -v gpgconf > /dev/null && gpgconf --kill all; \ + rm -rf "$GNUPGHOME"; \ \ mkdir -p nginx-${APP_MAJOR}; \ tar -xzvf nginx.tar.gz -C nginx-${APP_MAJOR} --strip-components 1; \ @@ -144,11 +151,24 @@ RUN set -eux; \ cd /; \ rm -rf /nginx-${APP_MAJOR}; \ ln -sf /srv/conf/nginx/nginx.conf /etc/nginx/nginx.conf; \ + \ +# 设置临时目录的权限信息,设置为777是为了保证后续使用`--user`或`gosu`时,可以更改目录对应的用户属性信息;运行时会被更改为700或755 chown -Rf nginx:nginx /etc/nginx /srv/conf/nginx /var/log/nginx /var/run/nginx /var/cache/nginx; \ -# this 777 will be replaced by 700 or 755 at runtime (allows semi-arbitrary "--user" values) chmod 777 /etc/nginx /srv/conf/nginx /var/log/nginx /var/run/nginx /var/cache/nginx; \ \ - apt purge -y --auto-remove ${fetchDeps}; \ +# 查找新安装的应用相应的依赖软件包,并表示为'manual',防止后续自动清理时被删除 + apt-mark auto '.*' > /dev/null; \ + { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; }; \ + find /usr/local -type f -executable -exec ldd '{}' ';' \ + | awk '/=>/ { print $(NF-1) }' \ + | sort -u \ + | xargs -r dpkg-query --search \ + | cut -d: -f1 \ + | sort -u \ + | xargs -r apt-mark manual; \ + \ +# 删除临时软件包,清理缓存 + apt purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $fetchDeps; \ apt autoclean -y; \ rm -rf /var/lib/apt/lists/*; diff --git a/1.16.1/entrypoint.sh b/1.16/entrypoint.sh similarity index 100% rename from 1.16.1/entrypoint.sh rename to 1.16/entrypoint.sh diff --git a/1.16.1/nginx/conf.d/default.conf b/1.16/nginx/conf.d/default.conf similarity index 100% rename from 1.16.1/nginx/conf.d/default.conf rename to 1.16/nginx/conf.d/default.conf diff --git a/1.16.1/nginx/nginx.conf.default b/1.16/nginx/nginx.conf.default similarity index 100% rename from 1.16.1/nginx/nginx.conf.default rename to 1.16/nginx/nginx.conf.default diff --git a/README.md b/README.md index 78d1cc7..a8ef5ca 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,17 @@ -# Nginx Ubuntu +# Nginx 基于的 Ubuntu(18.04) 系统的 Nginx 镜像,用于提供 WEB(nginx) 服务。 -## 基本信息 +**版本信息:** -* 镜像地址:endial/nginx:1.16.1 - * 依赖镜像:endial/ubuntu:18.04 +- 1.16.1、latest + +**镜像信息:** + +* 镜像地址:colovu/nginx:latest + * 依赖镜像:colovu/ubuntu:latest @@ -54,7 +58,7 @@ docker run -d --name nginx \ -v /host/dir/to/www:/srv/www:ro \ -v /host/dir/to/log:/var/log \ -v /host/dir/to/conf:/srv/conf \ - endial/nginx:1.16.1 + colovu/nginx:latest ``` 使用宿主机用户(如`www-data`用户)生成新的容器: @@ -66,7 +70,7 @@ docker run -d --name nginx \ -v /host/dir/to/www:/srv/www:ro \ -v /host/dir/to/log:/var/log \ -v /host/dir/to/conf:/srv/conf \ - endial/nginx:1.16.1 + colovu/nginx:latest ``` > 注意:如果使用自定义用户创建容器,且需要使用数据卷,可以有两种方式确保权限正确: @@ -80,7 +84,7 @@ docker run -d --name nginx \ docker run -d --name nginx \ -p 80:8080 \ --volumes-from dvc \ - endial/nginx:1.16.1 + colovu/nginx:latest ``` @@ -114,5 +118,5 @@ docker stop nginx ---- -本文原始来源 [Endial Fang](https://github.com/endial) @ [Github.com](https://github.com) +本文原始来源 [Endial Fang](https://github.com/colovu) @ [Github.com](https://github.com)