2019-11-06 14:53:09 +08:00
|
|
|
|
# [Nginx](https://hub.docker.com/_/nginx/)
|
2016-12-10 17:00:25 +08:00
|
|
|
|
|
2019-11-06 14:53:09 +08:00
|
|
|
|
## 基本信息
|
2017-11-24 10:19:15 +08:00
|
|
|
|
|
2016-12-10 17:00:25 +08:00
|
|
|
|
[Nginx](https://en.wikipedia.org/wiki/Nginx) 是开源的高效的 Web 服务器实现,支持 HTTP、HTTPS、SMTP、POP3、IMAP 等协议。
|
|
|
|
|
|
2020-06-17 00:42:01 +08:00
|
|
|
|
该仓库位于 `https://hub.docker.com/_/nginx/` ,提供了 Nginx 1.0 ~ 1.19.x 各个版本的镜像。
|
2016-12-10 17:00:25 +08:00
|
|
|
|
|
2019-11-06 14:53:09 +08:00
|
|
|
|
## 使用方法
|
2017-11-24 10:19:15 +08:00
|
|
|
|
|
2016-12-10 17:00:25 +08:00
|
|
|
|
下面的命令将作为一个静态页面服务器启动。
|
|
|
|
|
|
2017-11-22 11:13:23 +08:00
|
|
|
|
```bash
|
2016-12-10 17:00:25 +08:00
|
|
|
|
$ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx
|
|
|
|
|
```
|
2017-11-24 10:19:15 +08:00
|
|
|
|
|
2016-12-10 17:00:25 +08:00
|
|
|
|
用户也可以不使用这种映射方式,通过利用 Dockerfile 来直接将静态页面内容放到镜像中,内容为
|
|
|
|
|
|
2021-03-20 11:22:13 +08:00
|
|
|
|
```docker
|
2016-12-10 17:00:25 +08:00
|
|
|
|
FROM nginx
|
|
|
|
|
COPY static-html-directory /usr/share/nginx/html
|
|
|
|
|
```
|
2017-11-24 10:19:15 +08:00
|
|
|
|
|
2016-12-10 17:00:25 +08:00
|
|
|
|
之后生成新的镜像,并启动一个容器。
|
|
|
|
|
|
2017-11-22 11:13:23 +08:00
|
|
|
|
```bash
|
2016-12-10 17:00:25 +08:00
|
|
|
|
$ docker build -t some-content-nginx .
|
|
|
|
|
$ docker run --name some-nginx -d some-content-nginx
|
|
|
|
|
```
|
2017-11-24 10:19:15 +08:00
|
|
|
|
|
2016-12-10 17:00:25 +08:00
|
|
|
|
开放端口,并映射到本地的 `8080` 端口。
|
|
|
|
|
|
2017-11-22 11:13:23 +08:00
|
|
|
|
```bash
|
2017-12-01 17:32:39 +08:00
|
|
|
|
$ docker run --name some-nginx -d -p 8080:80 some-content-nginx
|
2016-12-10 17:00:25 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Nginx的默认配置文件路径为 `/etc/nginx/nginx.conf`,可以通过映射它来使用本地的配置文件,例如
|
|
|
|
|
|
2017-11-22 11:13:23 +08:00
|
|
|
|
```bash
|
2017-12-01 17:32:39 +08:00
|
|
|
|
$ docker run -d \
|
|
|
|
|
--name some-nginx \
|
2021-03-20 11:22:13 +08:00
|
|
|
|
-p 8080:80 \
|
|
|
|
|
-v /path/nginx.conf:/etc/nginx/nginx.conf:ro \
|
2017-12-01 17:32:39 +08:00
|
|
|
|
nginx
|
2016-12-10 17:00:25 +08:00
|
|
|
|
```
|
2017-11-24 10:19:15 +08:00
|
|
|
|
|
2019-11-06 14:53:09 +08:00
|
|
|
|
## Dockerfile
|
2017-02-07 22:04:05 +08:00
|
|
|
|
|
2017-11-01 00:36:57 +08:00
|
|
|
|
请到 https://github.com/docker-library/docs/tree/master/nginx 查看。
|