1.拉取镜像
$ docker pull nginx
显示拉取的镜像
$ docker images
2 启动容器
docker run -p 80:80 -d --name nginx-temp nginx:latest
3 创建外挂配置nginx的目录
mkdir /mydata/nginx/logs -p
mkdir /mydata/nginx/html -p
mkdir /mydata/nginx/conf -p
4 复制nginx容器的配置
cd /mydata/nginx
docker cp nginx:/etc/nginx/nginx.conf $PWD/conf
docker cp nginx:/etc/nginx/conf.d $PWD/conf
docker cp nginx:/usr/share/nginx/html/50x.html $PWD/html
docker cp nginx:/usr/share/nginx/html/index.html $PWD/html
5 删除临时容器
docker rm -f nginx-temp
6 启动Nginx容器并挂载数据
docker run --name my-custom-nginx -p 80:80 \
-v /mydata/nginx/html:/usr/share/nginx/html \
-v /mydata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /mydata/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /mydata/nginx/logs:/var/log/nginx \
-d nginx:latest
7 测试页面
http://[yourwebsite]