Hexo

点滴积累 豁达处之

0%

docker搭建nginx

docker容器技术

拉取官方的镜像

1
docker pull nginx:1.18.0

准备挂载文件

1
2
3
mkdir /usr/local/volume/nginx
mkdir /usr/local/volume/nginx/conf.d
mkdir /usr/local/volume/nginx/html

启动容器

1
docker run --name mynginx -d nginx:1.18.0

填充挂载文件

1
2
3
docker cp mynginx:/etc/nginx/nginx.conf /usr/local/volume/nginx/nginx.conf
docker cp mynginx:/etc/nginx/conf.d/default.conf /usr/local/volume/nginx/conf.d/default.conf
docker cp mynginx:/usr/share/nginx/html/index.html /usr/local/volume/nginx/html/index.html

删除容器

1
docker rm -f mynginx

启动并挂载

1
2
3
4
5
6
docker run -p 443:443 -p 80:80 --name mynginx   \
-v /usr/local/volume/nginx/html:/usr/share/nginx/html \
-v /usr/local/volume/nginx/log:/var/log/nginx \
-v /usr/local/volume/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /usr/local/volume/nginx/conf.d:/etc/nginx/conf.d \
-d nginx:1.18.0;