docker 安装 Nginx

  1. 搜索Nginx镜像

docker search nginx
执行结果如下

user@user-mini ~ % docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 15194 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 2049 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 816 [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 219
linuxserver/nginx An Nginx container, brought to you by LinuxS… 149
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 136 [OK]
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 124 [OK]
alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 102 [OK]
jasonrivers/nginx-rtmp Docker images to host RTMP streams using NGI… 92 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 70 [OK]
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 56 [OK]
nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers fo… 55
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 45
staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 24 [OK]
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN… 19
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19 [OK]
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 15
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13
raulr/nginx-wordpress Nginx front-end for the official wordpress:f… 13 [OK]
flashspys/nginx-static Super Lightweight Nginx Image 10 [OK]
mailu/nginx Mailu nginx frontend 9 [OK]
sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 2 [OK]
travix/nginx NGinx reverse proxy 2 [OK]
wodby/nginx Generic nginx 1 [OK]
2.拉去Nginx镜像
docker pull nginx
执行结果如下

user@user-mini ~ % docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
33847f680f63: Pull complete
dbb907d5159d: Pull complete
8a268f30c42a: Pull complete
b10cf527a02d: Pull complete
c90b090c213b: Pull complete
1f41b2f2bf94: Pull complete
Digest: sha256:c308ab347d1b3e20e33f9c3f77faf5afe89f579056e13fa26576016b8e850d3d
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
3.查看拉取到本地的镜像
docker images nginx
执行结果如下

REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 08b152afcfae 4 hours ago 133MB
4.创建Nginx容器
user@user-mini ~ % docker run -d --name nginx -p 80:80 08b
执行结果如下

user@user-mini ~ % docker run -d --name nginx -p 80:80 08b
7a576b38e3ecf92d148cd400493e6d89be0135b427005bfd79b23766460c4618
-d 指定容器以守护进程方式在后台运行
--name 指定容器名称,此处我指定的是nginx
-p 指定主机与容器内部的端口号映射关系,格式 -p
[宿主机端口号]:[容器内部端口],此处我使用了主机80端口,映射容器80端口
08b 是nginx的镜像IMAGE ID前3位
5.查看容器启动情况
user@user-mini ~ % docker ps -a
执行结果如下

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7a576b38e3ec 08b "/docker-entrypoint.…" 8 seconds ago Up 7 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp nginx
6.验证
在浏览器中输入IP 地址+端口号80 回车(由于我在本地搭建的所以输入了 127.0.0.1:80),出现如下图证明Nginx容器创建并启动成功了。

上一篇:Centos 基于Docker的Nginx安装


下一篇:【系列3】使用Dockerfile创建带编译安装nginx服务的Centos Docker镜像