安装
Docker拉取Nginx镜像:
docker pull nginx
docker images
创建挂载目录:
mkdir -p /Users/acton_zhang/mydocker/mynginx/{conf,conf.d,html,logs}
进入容器并查看配置文件目录结构:
docker run -i -t nginx /bin/bash
copy容器里的配置文件到宿主机刚创建的文件下面:
docker cp 4d65624dc26c:/etc/nginx/nginx.conf /Users/acton_zhang/mydocker/mynginx/conf/nginx.conf
docker cp 4d65624dc26c:/etc/nginx/conf.d/default.conf /Users/acton_zhang/mydocker/mynginx/conf.d/default.conf
编写default.conf配置文件:
将端口改为81:
挂载并启动Nginx:
docker run -p 81:81 --name mynginx --privileged=true -v /Users/acton_zhang/mydocker/mynginx/html:/usr/share/nginx/html -v /Users/acton_zhang/mydocker/mynginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /Users/acton_zhang/mydocker/mynginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /Users/acton_zhang/mydocker/mynginx/logs:/var/log/nginx -d nginx
编写好html文件放入html里面,之后在浏览器输入http://ip:81端口: