2016-12-10 17:00:25 +08:00
|
|
|
## [Nginx](https://hub.docker.com/_/nginx/)
|
|
|
|
|
|
|
|
### 基本信息
|
|
|
|
[Nginx](https://en.wikipedia.org/wiki/Nginx) 是开源的高效的 Web 服务器实现,支持 HTTP、HTTPS、SMTP、POP3、IMAP 等协议。
|
|
|
|
|
2017-02-07 22:04:05 +08:00
|
|
|
该仓库位于 https://hub.docker.com/_/nginx/ ,提供了 Nginx 1.0 ~ 1.11.x 各个版本的镜像。
|
2016-12-10 17:00:25 +08:00
|
|
|
|
|
|
|
### 使用方法
|
|
|
|
下面的命令将作为一个静态页面服务器启动。
|
|
|
|
|
|
|
|
```
|
|
|
|
$ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx
|
|
|
|
```
|
|
|
|
用户也可以不使用这种映射方式,通过利用 Dockerfile 来直接将静态页面内容放到镜像中,内容为
|
|
|
|
|
|
|
|
```
|
|
|
|
FROM nginx
|
|
|
|
COPY static-html-directory /usr/share/nginx/html
|
|
|
|
```
|
|
|
|
之后生成新的镜像,并启动一个容器。
|
|
|
|
|
|
|
|
```
|
|
|
|
$ docker build -t some-content-nginx .
|
|
|
|
$ docker run --name some-nginx -d some-content-nginx
|
|
|
|
```
|
|
|
|
开放端口,并映射到本地的 `8080` 端口。
|
|
|
|
|
|
|
|
```
|
|
|
|
docker run --name some-nginx -d -p 8080:80 some-content-nginx
|
|
|
|
```
|
|
|
|
|
|
|
|
Nginx的默认配置文件路径为 `/etc/nginx/nginx.conf`,可以通过映射它来使用本地的配置文件,例如
|
|
|
|
|
|
|
|
```
|
|
|
|
docker run --name some-nginx -v /some/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
|
|
|
|
```
|
|
|
|
使用配置文件时,为了在容器中正常运行,需要保持 `daemon off;`。
|
|
|
|
|
|
|
|
### Dockerfile
|
|
|
|
#### stable 版本
|
|
|
|
```
|
|
|
|
FROM debian:jessie
|
|
|
|
|
|
|
|
MAINTAINER NGINX Docker Maintainers "docker-maint@nginx.com"
|
|
|
|
|
|
|
|
ENV NGINX_VERSION 1.10.1-1~jessie
|
|
|
|
|
|
|
|
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \
|
|
|
|
&& echo "deb http://nginx.org/packages/debian/ jessie nginx" >> /etc/apt/sources.list \
|
|
|
|
&& apt-get update \
|
|
|
|
&& apt-get install --no-install-recommends --no-install-suggests -y \
|
|
|
|
ca-certificates \
|
|
|
|
nginx=${NGINX_VERSION} \
|
|
|
|
nginx-module-xslt \
|
|
|
|
nginx-module-geoip \
|
|
|
|
nginx-module-image-filter \
|
|
|
|
nginx-module-perl \
|
|
|
|
nginx-module-njs \
|
|
|
|
gettext-base \
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
# forward request and error logs to docker log collector
|
|
|
|
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
|
|
|
|
&& ln -sf /dev/stderr /var/log/nginx/error.log
|
|
|
|
|
|
|
|
EXPOSE 80 443
|
|
|
|
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 1.11.x 版本
|
|
|
|
|
|
|
|
```
|
|
|
|
FROM debian:jessie
|
|
|
|
|
|
|
|
MAINTAINER NGINX Docker Maintainers "docker-maint@nginx.com"
|
|
|
|
|
|
|
|
ENV NGINX_VERSION 1.11.1-1~jessie
|
|
|
|
|
|
|
|
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 \
|
|
|
|
&& echo "deb http://nginx.org/packages/mainline/debian/ jessie nginx" >> /etc/apt/sources.list \
|
|
|
|
&& apt-get update \
|
|
|
|
&& apt-get install --no-install-recommends --no-install-suggests -y \
|
|
|
|
ca-certificates \
|
|
|
|
nginx=${NGINX_VERSION} \
|
|
|
|
nginx-module-xslt \
|
|
|
|
nginx-module-geoip \
|
|
|
|
nginx-module-image-filter \
|
|
|
|
nginx-module-perl \
|
|
|
|
nginx-module-njs \
|
|
|
|
gettext-base \
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
# forward request and error logs to docker log collector
|
|
|
|
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
|
|
|
|
&& ln -sf /dev/stderr /var/log/nginx/error.log
|
|
|
|
|
|
|
|
EXPOSE 80 443
|
|
|
|
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|
|
|
|
```
|
2017-02-07 22:04:05 +08:00
|
|
|
|
|
|
|
|