Dokcer部署Nginx

Dokcer部署Nginx

搜索Nginx

在安装前必须要确认Nginx是否存在,可以使用两种方式来确认。

使用搜索命令来查找

使用命令后发现第一个就是我们需要的。

[root@localhost ~]# docker search nginx
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                              Official build of Nginx.                        14291     [OK]       
jwilder/nginx-proxy                Automated Nginx reverse proxy for docker con…   1941                 [OK]
richarvey/nginx-php-fpm            Container running Nginx + PHP-FPM capable of…   801                  [OK]
linuxserver/nginx                  An Nginx container, brought to you by LinuxS…   139                  
jc21/nginx-proxy-manager           Docker container for managing Nginx proxy ho…   132                  
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        82                   [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                   
flashspys/nginx-static             Super Lightweight Nginx Image                   8                    [OK]
mailu/nginx                        Mailu nginx frontend                            8                    [OK]
bitwarden/nginx                    The Bitwarden nginx web server acting as a r…   7                    
bitnami/nginx-ingress-controller   Bitnami Docker Image for NGINX Ingress Contr…   7                    [OK]
ansibleplaybookbundle/nginx-apb    An APB to deploy NGINX                          2                    [OK]
wodby/nginx                        Generic nginx                                   1                    [OK]

在Docker镜像站搜索(推荐)

镜像站地址:https://hub.docker.com/

提示:在这里可以看到镜像的详细信息。

  • 在搜索框输入Nginx然后点击搜索按钮,得到的第一条就是我们需要的。

  • 搜索到以后就点击进去进行下载Nginx,进入以后可以看到红色框中的内容将它复制,然后粘贴到终端里进行下载。

下载镜像

[root@localhost ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a076a628af6f: Already exists 
0732ab25fa22: Pull complete 
d7f36f6fe38f: Pull complete 
f72584a26f32: Pull complete 
7125e4df9063: Pull complete 
Digest: sha256:10b8cc432d56da8b61b070f4c7d2543a9ed17c2b23010b43af434fd40e2ca4aa
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

启动镜像

[root@localhost ~]# docker run -d --name nginx01 -p 3344:80 nginx
WARNING: IPv4 forwarding is disabled. Networking will not work.
42e0442c7df0c1e44b0009a1f959533da12fb293ae4277db210a6acbd2386070
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                  NAMES
42e0442c7df0   nginx     "/docker-entrypoint.…"   21 seconds ago   Up 19 seconds   0.0.0.0:3344->80/tcp   nginx01
46c4eb213ce8   centos    "/bin/bash"              13 hours ago     Up 13 hours                            vigorous_aryabhata
[root@localhost ~]# 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>

进入镜像

[root@localhost ~]# docker exec -it nginx01 /bin/bash
root@42e0442c7df0:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx