需求:挂载本地nginx配置文件到nginx容器内部使用 挂载静态页面到nginx容器内部
http://192.168.56.128:81/hello.html 可以访问到nginx容器中的页面。
Centos7 安装 Nginx:https://liush.blog.csdn.net/article/details/125027693
docker pull nginx
反向代理容器内部/opt目录下的静态资源
2.1 在虚拟机opt目录下创建子目录
mkdir /opt/nginxconf
mkdir /opt/html
2.2 编辑hello.html
vim /opt/html/hello.html
2.3 拷贝nginx配置文件到子目录下
cp /usr/local/nginx/conf/nginx.conf /opt/nginxconf
2.4 修改nginx配置:
location / {root /opt;
}
① 创建启动守护式容器,命名mynginx,映射虚拟机端口85指定容器nginx默认端口80,挂载虚拟机目录/opt/html/到容器目录/opt下
docker run -d --name mynginx -p 85:80 -v /opt/html/:/opt nginx
② 拷贝虚拟机文件到 命名为 mynginx 容器目录 /etc/nginx 下
docker cp /opt/nginxconf/nginx.conf mynginx:/etc/nginx/
③ 重启容器 mynginx
docker restart mynginx
http://192.168.56.128:85/hello.html