1、创建目录 1.1、创建目录
mkidr /opt/nginx/{conf,html,logs}
1.2修改权限
chmod +777 /opt/nginx/{conf,html,logs}
2、复制nginx容器中的配置文件
2.1、拉取nginx镜像
docker pull nginx
2.2、启动一个nginx测试容器
docker run -p 80:80 --name nginxtest -d nginx
2.3 从测试容器中复制nginx配置文件
docker cp nginxtest:/etc/nginx /opt/nginx/conf
3、删掉测试容器
先关闭容器
docker stop nginxtest
删除容器
docker rm nginxtest
4、启动正式的容器
docker run -d \
--name nginx \
-p 80:80 \
-v /opt/nginx/logs:/var/logs/nginx \
-v /opt/nginx/html:/usr/share/nginx/html \
-v /opt/nginx/conf:/etc/nginx \
nginx
5、测试 在html目录下创建一个index.html内容:
<h1>xmall</h1>
访问地址:http://ip