Docker部署nginx
1.搜索nginx的镜像信息:docker search nginx,查询到nginx对应的信息
cdc@cdcs-MacBook-Pro / % docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 14270 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1939 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 799 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 138
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 128
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 109 [OK]
bitnami/nginx Bitnami nginx Docker Image 93 [OK]
alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 86 [OK]
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 79 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 65 [OK]
nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 46
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 44 [OK]
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 28
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19 [OK]
staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 16 [OK]
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 15
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter 15
raulr/nginx-wordpress Nginx front-end for the official wordpress:f… 13 [OK]
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13
mailu/nginx Mailu nginx frontend 8 [OK]
flashspys/nginx-static Super Lightweight Nginx Image 8 [OK]
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 7 [OK]
navidonskis/nginx-php5.6 Docker nginx + php5.6 on Ubuntu 7 [OK]
wodby/nginx Generic nginx 1 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX
2.拉取nginx镜像信息,不加版本信息,默认拉取最新版本
cdc@cdcs-MacBook-Pro / % docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
6ec7b7d162b2: Pull complete
cb420a90068e: Pull complete
2766c0bf2b07: Pull complete
e05167b6a99d: Pull complete
70ac9d795e79: Pull complete
Digest: sha256:4cf620a5c81390ee209398ecc18e5fb9dd0f5155cd82adcbae532fec94006fb9
Status: Downloaded newer image
3.查看是否拉取成功:docker images,查看所有镜像文件
cdc@cdcs-MacBook-Pro / % docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker101tutorial latest bdbe87be83dd 45 hours ago 27.7MB
alpine/git latest ed0ba0fc6585 2 weeks ago 28.4MB
nginx latest ae2feff98a0c 3 weeks ago 133MB
centos latest 300e315adb2f 4 weeks ago 209MB
hello-world latest bf756fb1ae65 12 months ago 13.3kB
4. 通过:docker run -d,后台运行nginx容器,docker run -d --name test_nginx -p 3344:80 nginx
-d 后台运行
–name 给容器命名
-p 宿主机端口:容器内端口,可通过宿主机端口访问到容器内到端口
cdc@cdcs-MacBook-Pro / % docker run -d --name test_nginx -p 3344:80 nginx
cc2e021c959a3875e769b31bfaac03760920e2e356851d69ff5d7422c2759ad8
5.通过:curl访问刚刚运行的容器信息,自测
cdc@cdcs-MacBook-Pro / % curl localhost:3344
<!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>
6.在外部直接访问刚刚开放的nginx服务
7.部署ok