1.拉取镜像
docker pull nginx
2.创建容器
docker run --name my-nginx -p 80:80 -d nginx
3.找个文件夹创建以下目录,mkdir -p {conf,conf.d,html,logs}
4.从创建的nginx容器中复制配置文件到本地目录
9a2becc47dfc是你创建的nginx容器id,docker cp 容器ID:源位置 目标位置
docker cp 9a2becc47dfc:/etc/nginx/nginx.conf /Users/zhangcheng/Desktop/project/docker/nginx/conf
docker cp 9a2becc47dfc:/etc/nginx/conf.d/default.conf /Users/zhangcheng/Desktop/project/docker/nginx/conf.d
5.删除容器
docker rm 9a2becc47dfc
6.创建新容器
创建容器并挂载目录
docker run --name my_nginx -d \ -p 80:80 \ -v /Users/zhangcheng/Desktop/project/docker/nginx/html:/usr/share/nginx/html \ -v /Users/zhangcheng/Desktop/project/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \ -v /Users/zhangcheng/Desktop/project/docker/nginx/conf.d:/etc/nginx/conf.d \ -v /Users/zhangcheng/Desktop/project/docker/nginx/logs:/var/log/nginx \ nginx
7.在html目录创建index.html
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
8.访问 http://localhost/
标签:Users,Desktop,nginx,html,conf,docker,安装 From: https://www.cnblogs.com/gstszbc/p/18222585