- 1.下载镜像
docker pull nginx:latest
- 2.创建nginx挂载目录
mkdir -p /data/docker/nginx/conf mkdir -p /data/docker/nginx/html mkdir -p /data/docker/nginx/log
- 3.简单容器启动重启
docker run --name nginx -p 80:80 -d nginx
- 4.将容器中nginx相关文件复制到宿主机挂载目录
docker cp nginx:/etc/nginx/nginx.conf /data/docker/nginx/conf/nginx.conf docker cp nginx:/etc/nginx/conf.d /data/docker/nginx/conf/conf.d docker cp nginx:/usr/share/nginx/html /data/docker/nginx/
- 5.删除简单容器,准备正式启动
docker rm -f nginx
docker run -d -p 5000:80 --name nginx --restart=always \ -v /data/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \ -v /data/docker/nginx/conf/conf.d:/etc/nginx/conf.d \ -v /data/docker/nginx/log:/var/log/nginx \ -v /data/docker/nginx/html:/usr/share/nginx/html \ nginx
docker部署nginx
于 2023-03-23 14:41:41 首次发布