安装Nginx
# 搜索Nginx docker search nginx # 根据版本选择相应的nginx拉取镜像 docker pull nginx:[版本号] # docker pull nginx 不带版本号默认选择最新的镜像拉取 # 查看所有=镜像 docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 0e901e68141f 2 weeks ago 142MB centos latest 5d0da3dc9764 9 months ago 231MB # 开启宿主机的3344端口 firewall-cmd --zone=public --add-port=3344/tcp --permanent systemctl restart firewalld.service firewall-cmd --list-ports # 运行nginx容器 docker run -d --name nginx01 -p 3344:80 nginx ### 运行测试 # -d 后台运行 # --name 给容器命名 # -p 宿主机端口:容器内部端口 curl localhost:3344 <!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>
端口暴露的概念
# 交互模式进入容器 docker exec -it nginx01 /bin/bash root@e5347a513358:/# whereis nginx nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx root@e5347a513358:/# cd /etc/nginx root@e5347a513358:/etc/nginx#
问题:每次改动 Nginx 配置文件,都需要进入容器内部,十分麻烦!要是可以在容器外部提供一个映射路径,达到在容器内修改文件的效果,那么容器内部就可以自动修改 -v 数据卷
参考文档:
https://blog.csdn.net/Wei_Naijia/article/details/125542855
标签:容器,--,3344,拉取,nginx,镜像,Docker,docker From: https://www.cnblogs.com/jelly12345/p/17035982.html