docker安装nginx

1、拉取镜像

docker pull nginx:latest

2、创建目录

mkdir -p /opt/nginx/conf
mkdir -p /opt/nginx/html
mkdir -p /opt/nginx/log

3、生成容器

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

4、将容器文件复制到宿主机

docker cp nginx:/etc/nginx/nginx.conf /opt/nginx/conf/nginx.conf

docker cp nginx:/etc/nginx/conf.d /opt/nginx/conf/conf.d

docker cp nginx:/usr/share/nginx/html /opt/nginx/

5、停止并删除容器

# 找到nginx对应的容器id
docker ps -a
# 关闭该容器
docker stop nginx
# 删除该容器
docker rm nginx

6、挂载配置文件启动容器

docker run -p 80:80 --name nginx -v /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /opt/nginx/conf/conf.d:/etc/nginx/conf.d -v /opt/nginx/log:/var/log/nginx -v /opt/nginx/html:/usr/share/nginx/html -d nginx:latest

你可能感兴趣的:(nginx,docker,运维)