docker安装nginx
1.查找镜像
docker search命令查找,也可以去docker hub(https://hub.docker.com)上搜索!!!
[root@localhost ~]# docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 17733 [OK] linuxserver/nginx An Nginx container, brought to you by LinuxS… 181 bitnami/nginx Bitnami nginx Docker Image 143 [OK] ubuntu/nginx Nginx, a high-performance reverse proxy & we… 67 bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 22 [OK] rancher/nginx-ingress-controller 11 ibmcom/nginx-ingress-controller Docker Image for IBM Cloud Private-CE (Commu… 4 bitnami/nginx-ldap-auth-daemon 3 bitnami/nginx-exporter 3 kasmweb/nginx An Nginx image based off nginx:alpine and in… 3 rancher/nginx 2 vmware/nginx 2 rancher/nginx-ingress-controller-defaultbackend 2 rapidfort/nginx RapidFort optimized, hardened image for NGINX 2 circleci/nginx This image is for internal use 2 wallarm/nginx-ingress-controller Kubernetes Ingress Controller with Wallarm e… 1 vmware/nginx-photon 1 bitnami/nginx-intel 1 rapidfort/nginx-ib RapidFort optimized, hardened image for NGIN… 0 ibmcom/nginx-ingress-controller-ppc64le Docker Image for IBM Cloud Private-CE (Commu… 0 rancher/nginx-conf 0 rancher/nginx-ssl 0 continuumio/nginx-ingress-ws 0 rancher/nginx-ingress-controller-amd64 0 ibmcom/nginx-ppc64le Docker image for nginx-ppc64le 0
2.下载镜像
[root@localhost ~]# docker pull nginx
3.运行测试
//-p表示暴漏端口 命令:-p:宿主机端口:容器内部端口 //将nginx01的80端口映射到宿主机的3344端口 [root@localhost ~]# docker run -d --name nginx01 -p 3344:80 nginx 0088cd8839470a433f559547fbd7037fc43802b16e0f4da3aa3df1e61a5a8889 [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0088cd883947 nginx "/docker-entrypoint.…" 15 seconds ago Up 13 seconds 0.0.0.0:3344->80/tcp nginx01 //本地访问刚才映射的3344端口测试 [root@localhost ~]# 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>
4.进入容器
[root@localhost ~]# docker exec -it nginx01 /bin/bash root@0088cd883947:/# whereis nginx nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx root@0088cd883947:/# cd /etc/nginx root@0088cd883947:/etc/nginx# ls conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
5.停止容器服务
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0088cd883947 nginx "/docker-entrypoint.…" 30 minutes ago Up 30 minutes 0.0.0.0:3344->80/tcp nginx01 //使用stop命令停止 [root@localhost ~]# docker stop 0088cd883947 0088cd883947
停止服务后浏览器再访问会报错,因为刚才已经用stop命令将服务停止了。
以上,就是使用docker部署nginx的方法!部署其他应用则大同小异,多练习会熟能生巧!!!
附一张自己理解的端口暴露的概念,见下图:
标签:ingress,部署,nginx,0088cd883947,docker,root,localhost From: https://www.cnblogs.com/yzq-top/p/16925520.html