docker安装、测试、删除Nginx

1、首先搜索nginx镜像

[root@localhost ~]# docker search nginx
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                              Official build of Nginx.                        14852     [OK]       
jwilder/nginx-proxy                Automated Nginx reverse proxy for docker con…   2028                 [OK]
richarvey/nginx-php-fpm            Container running Nginx + PHP-FPM capable of…   813                  [OK]
jc21/nginx-proxy-manager           Docker container for managing Nginx proxy ho…   186                  
linuxserver/nginx                  An Nginx container, brought to you by LinuxS…   143                  
tiangolo/nginx-rtmp                Docker image with Nginx using the nginx-rtmp…   124                  [OK]
jlesage/nginx-proxy-manager        Docker container for Nginx Proxy Manager        107                  [OK]
bitnami/nginx                      Bitnami nginx Docker Image                      95                   [OK]
alfg/nginx-rtmp                    NGINX, nginx-rtmp-module and FFmpeg from sou…   94                   [OK]
nginxdemos/hello                   NGINX webserver that serves a simple page co…   68                   [OK]
privatebin/nginx-fpm-alpine        PrivateBin running on an Nginx, php-fpm & Al…   53                   [OK]
nginx/nginx-ingress                NGINX and  NGINX Plus Ingress Controllers fo…   51                   
nginxinc/nginx-unprivileged        Unprivileged NGINX Dockerfiles                  33                   
staticfloat/nginx-certbot          Opinionated setup for automatic TLS certs lo…   21                   [OK]
schmunk42/nginx-redirect           A very simple container to redirect HTTP tra…   19                   [OK]
nginx/nginx-prometheus-exporter    NGINX Prometheus Exporter for NGINX and NGIN…   17                   
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                   
bitwarden/nginx                    The Bitwarden nginx web server acting as a r…   12                   
flashspys/nginx-static             Super Lightweight Nginx Image                   10                   [OK]
bitnami/nginx-ingress-controller   Bitnami Docker Image for NGINX Ingress Contr…   8                    [OK]
mailu/nginx                        Mailu nginx frontend                            8                    [OK]
ansibleplaybookbundle/nginx-apb    An APB to deploy NGINX                          2                    [OK]
wodby/nginx                        Generic nginx                                   1                    [OK]
centos/nginx-110-centos7           Platform for running nginx 1.10 or building …   0            

2、下载nginx镜像

[root@localhost ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
69692152171a: Pull complete 
49f7d34d62c1: Pull complete 
5f97dc5d71ab: Pull complete 
cfcd0711b93a: Pull complete 
be6172d7651b: Pull complete 
de9813870342: Pull complete 
Digest: sha256:df13abe416e37eb3db4722840dd479b00ba193ac6606e7902331dcea50f4f1f2
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

3、查看下载的镜像是否成功

[root@localhost ~]# docker images
REPOSITORY           TAG       IMAGE ID       CREATED        SIZE
nginx                latest    f0b8a9a54136   18 hours ago   133MB
centos               latest    300e315adb2f   5 months ago   209MB
daocloud.io/centos   7         7e6257c9f8d8   9 months ago   203MB

4、运行nginx镜像

[root@localhost ~]# docker run -d --name nginx01 -h nginx01  -p 3344:80 nginx
9e30f3a2a54cb3f6900a34a0d5c8560b53372ae26f47ac5470c600ac9cff4250

5、查看运行后的容器

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                   NAMES
9e30f3a2a54c   nginx     "/docker-entrypoint.…"   29 seconds ago   Up 27 seconds   0.0.0.0:3344->80/tcp, :::3344->80/tcp   nginx01
011374ad8b27   centos    "/bin/bash"              2 hours ago      Up 35 minutes                                           dreamy_ptolemy

6、测试容器是否成功

[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@nginx01:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@nginx01:/# exit
exit
[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:92:7e:e9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.217.146/24 brd 192.168.217.255 scope global dynamic ens33
       valid_lft 1122sec preferred_lft 1122sec
    inet 192.168.217.147/24 brd 192.168.217.255 scope global secondary dynamic ens33
       valid_lft 1101sec preferred_lft 1101sec
    inet6 fe80::20c:29ff:fe92:7ee9/64 scope link 

还可以通过网页查看。
在这里插入图片描述

7、关闭容器

[root@localhost ~]# docker stop nginx01 
nginx01
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED       STATUS          PORTS     NAMES
011374ad8b27   centos    "/bin/bash"   2 hours ago   Up 39 minutes             dreamy_ptolemy
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS                      PORTS     NAMES
9e30f3a2a54c   nginx     "/docker-entrypoint.…"   4 minutes ago   Exited (0) 10 seconds ago             nginx01
011374ad8b27   centos    "/bin/bash"              2 hours ago     Up 39 minutes                         dreamy_ptolemy

8、删除容器

[root@localhost ~]# docker rm nginx01 
nginx01
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值