docker安装nginx并挂载容器外配置文件运行

1、新建文件夹

mkdir -p /home/docker-nginx/log
mkdir -p /home/docker-nginx/conf.d

2、运行nginx用于获取配置文件

docker run --name nginx -p 80:80 -d nginx

3、将配置文件和日志拷贝到容器外

docker cp nginx:/etc/nginx/nginx.conf /home/docker-nginx/
docker cp nginx:/var/log/nginx /home/docker-nginx/log
docker cp nginx:/etc/nginx/conf.d/default.conf /home/docker-nginx/conf.d/

4、删除初装nginx容器

docker ps并docker rm XXXXX删除

5、运行挂载容器外配置的nginx

docker run --name nginx -p 80:80 -v /home/docker-nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/docker-nginx/log:/var/log/nginx -v /home/docker-nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf -d nginx

 

你可能感兴趣的:(docker安装nginx并挂载容器外配置文件运行)