i386架构的Nginx官方Docker镜像,Nginx是一款开源的HTTP/HTTPS反向代理服务器、Web服务器、负载均衡器和HTTP缓存,以高并发、高性能和低内存占用为核心特点,支持多种网络协议。
注意
本仓库是https://hub.docker.com/_/nginx针对`i386`架构的"每架构"仓库——更多信息请参见官方镜像文档中的https://github.com/docker-library/official-images#architectures-other-than-amd64和官方镜像FAQ中的https://github.com/docker-library/faq#an-images-source-changed-in-git-now-what。
快速参考
-
维护者:
https://github.com/nginxinc/docker-nginx -
获取帮助:
https://dockr.ly/comm-slack、Server Fault、https://unix.stackexchange.com/help/on-topic或https://stackoverflow.com/help/on-topic
支持的标签及对应的Dockerfile链接
-
https://github.com/nginx/docker-nginx/blob/c3785f2653008f9354c3d29a54d8c5459c53fa60/mainline/debian/Dockerfile
-
https://github.com/nginx/docker-nginx/blob/c3785f2653008f9354c3d29a54d8c5459c53fa60/mainline/debian-perl/Dockerfile
-
https://github.com/nginx/docker-nginx/blob/c3785f2653008f9354c3d29a54d8c5459c53fa60/mainline/alpine/Dockerfile
-
https://github.com/nginx/docker-nginx/blob/c3785f2653008f9354c3d29a54d8c5459c53fa60/mainline/alpine-perl/Dockerfile
-
https://github.com/nginx/docker-nginx/blob/c3785f2653008f9354c3d29a54d8c5459c53fa60/mainline/alpine-slim/Dockerfile
-
https://github.com/nginx/docker-nginx/blob/9b549fdf936778810dbe95a4813899c60444ef1c/stable/debian/Dockerfile
-
https://github.com/nginx/docker-nginx/blob/7f1d49f6f222f7e588a9066fd53a0ce43c3466a5/stable/debian-perl/Dockerfile
-
https://github.com/nginx/docker-nginx/blob/7f1d49f6f222f7e588a9066fd53a0ce43c3466a5/stable/alpine/Dockerfile
-
https://github.com/nginx/docker-nginx/blob/7f1d49f6f222f7e588a9066fd53a0ce43c3466a5/stable/alpine-perl/Dockerfile
-
https://github.com/nginx/docker-nginx/blob/9b549fdf936778810dbe95a4813899c60444ef1c/stable/alpine-slim/Dockerfile
快速参考(续)
-
问题反馈地址:
https://github.com/nginxinc/docker-nginx/issues?q= -
支持的架构:(https://github.com/docker-library/official-images#architectures-other-than-amd64)
https://hub.docker.com/r/amd64/nginx/、https://hub.docker.com/r/arm32v5/nginx/、https://hub.docker.com/r/arm32v6/nginx/、https://hub.docker.com/r/arm32v7/nginx/、https://hub.docker.com/r/arm64v8/nginx/、https://hub.docker.com/r/i386/nginx/、https://hub.docker.com/r/mips64le/nginx/、https://hub.docker.com/r/ppc64le/nginx/、https://hub.docker.com/r/riscv64/nginx/、https://hub.docker.com/r/s390x/nginx/ -
镜像制品详情:
https://github.com/docker-library/repo-info/blob/master/repos/nginx (https://github.com/docker-library/repo-info/commits/master/repos/nginx)
(镜像元数据、传输大小等) -
镜像更新:
https://github.com/docker-library/official-images/issues?q=label%3Alibrary%2Fnginx
https://github.com/docker-library/official-images/blob/master/library/nginx (https://github.com/docker-library/official-images/commits/master/library/nginx) -
本描述的来源:
https://github.com/docker-library/docs/tree/master/nginx (https://github.com/docker-library/docs/commits/master/nginx)
什么是Nginx?
Nginx(发音为"engine-x")是一款开源的反向代理服务器,支持HTTP、HTTPS、SMTP、POP3和IMAP协议,同时也是负载均衡器、HTTP缓存和Web服务器(源服务器)。Nginx项目最初以高并发、高性能和低内存占用为核心目标。它采用2条款BSD类许可证授权,可运行于Linux、BSD变体、Mac OS X、Solaris、AIX、HP-UX以及其他类Unix系统,同时也提供了适用于Microsoft Windows的概念验证版本。
***.org/wiki/Nginx
如何使用此镜像
托管简单静态内容
console$ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d i386/nginx
或者,可通过简单的Dockerfile生成包含必要内容的新镜像(比上述绑定挂载方式更简洁):
dockerfileFROM docker.xuanyuan.run/i386/nginx COPY static-html-directory /usr/share/nginx/html
将此文件与内容目录("static-html-directory")放在同一目录,然后执行以下命令构建并启动容器:
console$ docker build -t some-content-nginx . $ docker run --name some-nginx -d some-content-nginx
暴露外部端口
console$ docker run --name some-nginx -d -p 8080:80 some-content-nginx
之后可通过浏览器访问http://localhost:8080或http://host-ip:8080。
自定义配置
可通过挂载配置文件或构建新镜像来自定义配置。
若需修改默认配置,可从运行中的nginx容器获取默认配置:
console$ docker run --rm --entrypoint=cat i386/nginx /etc/nginx/nginx.conf > /host/path/nginx.conf
然后在主机文件系统中编辑/host/path/nginx.conf。
有关nginx配置文件语法的详细信息,请参见http://nginx.org/en/docs/(特别是http://nginx.org/en/docs/beginners_guide.html#conf_structure)。
挂载配置文件
console$ docker run --name my-custom-nginx-container -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d i386/nginx
构建包含自定义配置的新镜像
dockerfileFROM docker.xuanyuan.run/i386/nginx COPY nginx.conf /etc/nginx/nginx.conf
若在Dockerfile中添加自定义CMD,需确保CMD中包含-g daemon off;,使nginx保持在前台运行,以便Docker正确跟踪进程(否则容器会在启动后立即停止)!
然后通过docker build -t custom-nginx .构建镜像,并按以下方式运行:
console$ docker run --name my-custom-nginx-container -d custom-nginx
在i386/nginx配置中使用环境变量(1.19版本新增)
默认情况下,i386/nginx不支持在大多数配置块中使用环境变量。但此镜像提供了一个功能,可在nginx启动前提取环境变量。
以下是使用compose.yaml的示例:
yamlweb: image: docker.xuanyuan.run/i386/nginx volumes: - ./templates:/etc/nginx/templates ports: - "8080:80" environment: - NGINX_HOST=foobar.com - NGINX_PORT=80
默认情况下,此功能会读取/etc/nginx/templates/*.template中的模板文件,并通过执行envsubst将结果输出到/etc/nginx/conf.d。
因此,若放置templates/default.conf.template文件,其中包含如下变量引用:
listen ${NGINX_PORT};
则会输出到/etc/nginx/conf.d/default.conf:
listen 80;
可通过以下环境变量修改此行为:
-
NGINX_ENVSUBST_TEMPLATE_DIR- 包含模板文件的目录(默认:
/etc/nginx/templates) - 若目录不存在,此功能将不处理模板
- 包含模板文件的目录(默认:
-
NGINX_ENVSUBST_TEMPLATE_SUFFIX- 模板文件的后缀(默认:
.template) - 仅处理以此后缀结尾的文件
- 模板文件的后缀(默认:
-
NGINX_ENVSUBST_OUTPUT_DIR- 执行envsubst后输出结果的目录(默认:
/etc/nginx/conf.d) - 输出文件名是移除后缀的模板文件名
- 例如:
/etc/nginx/templates/default.conf.template将输出为/etc/nginx/conf.d/default.conf
- 例如:
- 此目录必须可由运行容器的用户写入
- 执行envsubst后输出结果的目录(默认:
以只读模式运行i386/nginx
要以只读模式运行i386/nginx,需将Docker卷挂载到所有nginx需要写入的位置。默认配置要求对/var/cache/nginx和/var/run具有写权限。可通过以下命令实现:
console$ docker run -d -p 80:80 --read-only -v $(pwd)/nginx-cache:/var/cache/nginx -v $(pwd)/nginx-pid:/var/run nginx
若高级配置要求nginx写入其他位置,只需为这些位置添加更多卷挂载。
以调试模式运行nginx
1.9.8及以上版本的镜像包含nginx-debug二进制文件,在使用较高日志级别时会生成详细输出。可通过简单的CMD替换使用:
console$ docker run --name my-nginx -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d i386/nginx nginx-debug -g 'daemon off;'
compose.yaml中的类似配置如下:
yamlweb: image: docker.xuanyuan.run/i386/nginx volumes: - ./nginx.conf:/etc/nginx/nginx.conf:ro command: [nginx-debug, '-g', 'daemon off;']
入口点静默日志
1.19.0及以上版本添加了详细的入口点输出,提供容器启动过程的信息。可通过设置环境变量NGINX_ENTRYPOINT_QUIET_LOGS静默此输出:
console$ docker run -d -e NGINX_ENTRYPOINT_QUIET_LOGS=1 i386/nginx
用户和组ID
自1.17.0版本起,基于alpine和debian的镜像变体使用相同的用户和组ID来降低工作进程的权限:
console$ id uid=101(nginx) gid=101(nginx) groups=101(nginx)
以非root用户运行i386/nginx
可使用较低权限的任意UID/GID运行镜像,但需修改i386/nginx配置以使用该UID/GID对可写目录:
console$ docker run -d -v $PWD/nginx.conf:/etc/nginx/nginx.conf i386/nginx
当前目录中的nginx.conf需重新定义以下指令:
nginxpid /tmp/nginx.pid;
并在http上下文中:
nginxhttp { client_body_temp_path /tmp/client_temp; proxy_temp_path /tmp/proxy_temp_path; fastcgi_temp_path /tmp/fastcgi_temp; uwsgi_temp_path /tmp/uwsgi_temp; scgi_temp_path /tmp/scgi_temp; ... }
或者,可参考官方https://hub.docker.com/r/nginxinc/nginx-unprivileged。
镜像变体
i386/nginx镜像有多种版本,适用于不同使用场景。
i386/nginx:<version>
这是默认镜像。若不确定需求,建议使用此版本。它既可作为临时容器(挂载源代码并启动容器运行应用),也可作为构建其他镜像的基础。
部分标签可能包含bookworm或t
i386 命名空间的其他可用镜像:
镜像拉取方式
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
DockerHub 原生拉取命令
用户好评
来自真实用户的反馈,见证轩辕镜像的优质服务