docker 安裝 Nginx

首先你得保證你得docker是正確安裝沒有問題的。

1. 搜索Nginx鏡像

docker search nginx

執(zhí)行結果如下

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

執(zhí)行結果如下

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

執(zhí)行結果如下

REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    08b152afcfae   4 hours ago   133MB

4.創(chuàng)建Nginx容器

 user@user-mini ~ % docker run -d --name nginx -p 80:80 08b 

執(zhí)行結果如下

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

執(zhí)行結果如下

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),出現(xiàn)如下圖證明Nginx容器創(chuàng)建并啟動成功了。


image.png
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容