Docker安裝Nginx
阿新 • • 發佈:2020-08-16
Docker安裝Nginx
# 1、搜尋映象 推薦使用官網搜尋 docker search nginx [root@bogon home]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE # 2、拉取映象 [root@bogon home]# docker pull nginx Using default tag: latest latest: Pulling from library/nginx bf5952930446: Already exists ba755a256dfe: Pull complete c57dd87d0b93: Pull complete d7fbf29df889: Pull complete 1f1070938ccd: Pull complete Digest: sha256:36b74457bccb56fbf8b05f79c85569501b721d4db813b684391d63e02287c0b2 Status: Downloaded newer image for nginx:latest docker.io/library/nginx:latest [root@bogon home]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 08393e824c32 7 days ago 132MB #3、啟動映象 # docker run -d --name mynginx -p 4433:80 映象名 # --name mynginx # 給我們啟動的容器起個名字 # -p 4433:80 # 4433:80 主機埠與容器埠做對映 # 以互動模式啟動 [root@bogon ~]# docker run -it --name nginx02 -p 4433:80 nginx /bin/bash root@76564a344b1b:/# # 以後臺方式啟動 [root@bogon home]# docker run -d --name mynginx -p 4433:80 nginx b583310be4da6790918aab8234f260f9cbe9b3a06cc26d652c955a9aecff6751 # 開放4433埠 [root@bogon home]# firewall-cmd --zone=public --add-port=4433/tcp --permanent success # 重啟防火牆 [root@bogon home]# firewall-cmd --reload success # 檢視當前所有tcp埠· [root@bogon home]# netstat -ntlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1031/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1201/master tcp6 0 0 :::4433 :::* LISTEN 60497/docker-proxy tcp6 0 0 :::22 :::* LISTEN 1031/sshd tcp6 0 0 ::1:25 :::* LISTEN 1201/master # 檢視所有4433埠使用情況· [root@bogon home]# netstat -ntulp |grep 4433 tcp6 0 0 :::4433 :::* LISTEN 60497/docker-proxy [root@bogon home]# lsof -i:4433 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME docker-pr 60497 root 4u IPv6 286143 0t0 TCP *:vop (LISTEN) # 訪問Nginx 成功 [root@bogon home]# curl localhost:4433 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> 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> [root@bogon home]#