Docker 安装Nginx

1.首先获取nginx

docker pull nginx

2.安装nginx,将nginx对应的配置路径和文件映射到主机目录,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
docker run --name nginx \
-p 80:80 \
-p 443:443 \
-v /etc/localtime:/etc/localtime:ro \
-v /home/docker/nginx/wwwroot:/home/wwwroot \
-v /home/docker/nginx/config/nginx.conf:/etc/nginx/nginx.conf \
-v /home/docker/nginx/config/conf.d:/etc/nginx/conf.d \
-v /home/docker/nginx/config/logs:/var/log/nginx \
-v /home/docker/nginx/config/ssl:/etc/nginx/ssl \
-d \
--restart=always \
nginx