【docker】nginx的镜像使用

1.查看nginx的镜像

[root@es1 ~]# docker search nginx
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                              Official build of Nginx.                        19975     [OK]       
bitnami/nginx                      Bitnami container image for NGINX               190                  [OK]
nginxinc/nginx-unprivileged        Unprivileged NGINX Dockerfiles                  152                  
nginxproxy/nginx-proxy             Automated nginx proxy for Docker containers …   140                  
nginxproxy/acme-companion          Automated ACME SSL certificate generation fo…   134                  
ubuntu/nginx                       Nginx, a high-performance reverse proxy & we…   114                  
nginx/nginx-ingress                NGINX and  NGINX Plus Ingress Controllers fo…   92                   
nginx/unit                         This repository is retired, use the Docker o…   63                   
nginx/nginx-prometheus-exporter    NGINX Prometheus Exporter for NGINX and NGIN…   42                   
bitnami/nginx-ingress-controller   Bitnami container image for NGINX Ingress Co…   34                   [OK]
unit                               Official build of NGINX Unit: Universal Web …   32        [OK]       
nginxproxy/docker-gen              Generate files from docker container meta-da…   17                   
kasmweb/nginx                      An Nginx image based off nginx:alpine and in…   8                    
nginxinc/nginx-s3-gateway          Authenticating and caching gateway based on …   6                    
bitnami/nginx-exporter             Bitnami container image for NGINX Exporter      5                    
nginxinc/ingress-demo              Ingress Demo                                    4                    
nginx/nginx-ingress-operator       NGINX Ingress Operator for NGINX and NGINX P…   2                    
rancher/nginx                                                                      2                    
nginxinc/amplify-agent             NGINX Amplify Agent docker repository           1                    
nginx/nginx-quic-qns               NGINX QUIC interop                              1                    
nginxinc/mra-fakes3                                                                0                    
nginxinc/ngx-rust-tool                                                             0                    
nginxinc/mra_python_base                                                           0                    
nginx/unit-preview                 Unit preview features                           0                    

2.拉取nginx镜像 

docker pull nginx 
[root@es1 ~]# docker pull nginx 
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
a9edb18cadd1: Pull complete 
589b7251471a: Pull complete 
186b1aaa4aa6: Pull complete 
b4df32aa5a72: Pull complete 
a0bcbecc962e: Pull complete 
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

3.查看镜像 

[root@es1 ~]# docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    605c77e624dd   2 years ago   141MB
my_mysql     latest    3218b38490ce   2 years ago   516MB
mysql        latest    3218b38490ce   2 years ago   516MB
busybox      1.28.3    8ac48589692a   6 years ago   1.15MB

4.创建一个容器

--创建一个容器,容器名为sspu_8001,容器主机名sspu_8001,容器会自动启动,
--访问宿主机的8001 端口即可访问容器nginx,用镜像nginx:latest
docker container run -d0 nginx:latest --restart always
---可以简写,去掉container;
docker run -d  -p 8001:80 nginx:latest --restart always

[root@es1 ~]# docker container run -d --name sspu_8001 -h sspu_8001 -p 8001:80 nginx:latest --restart always
02d22335b4b66348433d30759f2a32e4352c0b05a26d8741283b499639f73a68
[root@es1 ~]# 

docker ps -a 
[root@es1 ~]# docker ps -a 
CONTAINER ID   IMAGE            COMMAND                  CREATED          STATUS                        PORTS                                   NAMES
02d22335b4b6   nginx:latest     "/docker-entrypoint.…"   20 seconds ago   Exited (127) 19 seconds ago                                           sspu_8001
056a2248ed19   mysql            "docker-entrypoint.s…"   4 hours ago      Up 4 hours                    3306/tcp, 33060/tcp                     mysql
19c0b91262fe   busybox:1.28.3   "/bin/sh"                4 hours ago      Up 4 hours                    0.0.0.0:2222->22/tcp, :::2222->22/tcp   linuxtools3
3b34c56b6721   busybox:1.28.3   "/bin/sh"                4 hours ago      Up 4 hours                                                            linuxtools

--启动容器 
always,在容器退出时总是重启容器。
--我们发现它总是处于退出状态。
--删除nginx容器 
[root@es1 ~]# docker rm 02d22335b4b6 
02d22335b4b6
--重新创建一个容器实例。
docker run -d --name sspu_8001 -h sspu_8001 -p 8001:80 nginx:latest 
[root@es1 ~]# docker run -d --name sspu_8001 -h sspu_8001 -p 8001:80 nginx:latest 
c9efee6deab9dae4e08e8c064ac54539c5d3c2135b5985d2833832c2f568aeff
[root@es1 ~]# docker ps -a
CONTAINER ID   IMAGE            COMMAND                  CREATED         STATUS                       PORTS                                   NAMES
c9efee6deab9   nginx:latest     "/docker-entrypoint.…"   4 seconds ago   Up 4 seconds                 0.0.0.0:8001->80/tcp, :::8001->80/tcp   sspu_8001
056a2248ed19   mysql            "docker-entrypoint.s…"   4 hours ago     Exited (137) 3 minutes ago                                           mysql
19c0b91262fe   busybox:1.28.3   "/bin/sh"                4 hours ago     Exited (137) 3 minutes ago                                           linuxtools3
3b34c56b6721   busybox:1.28.3   "/bin/sh"                4 hours ago     Exited (137) 3 minutes ago                                           linuxtools

--检查端口 
docker port c9efee6deab9
[root@es1 ~]# docker port c9efee6deab9
80/tcp -> 0.0.0.0:8001
80/tcp -> :::8001

docker port sspu_8001
[root@es1 ~]# docker port sspu_8001
80/tcp -> 0.0.0.0:8001
80/tcp -> :::8001


[root@es1 ~]# docker ps -ls
CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS              PORTS                                   NAMES       SIZE
c9efee6deab9   nginx:latest   "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:8001->80/tcp, :::8001->80/tcp   sspu_8001   1.09kB (virtual 141MB)

--登陆容器实例。
docker exec -it c9efee6deab9 /bin/bash
[root@es1 ~]# docker exec -it c9efee6deab9 /bin/bash
root@sspu_8001:/# 
root@sspu_8001:/# 
root@sspu_8001:/# ls -lsa
total 12
0 drwxr-xr-x   1 root root   39 Jul  2 11:38 .
0 drwxr-xr-x   1 root root   39 Jul  2 11:38 ..
0 -rwxr-xr-x   1 root root    0 Jul  2 11:38 .dockerenv
4 drwxr-xr-x   2 root root 4096 Dec 20  2021 bin
0 drwxr-xr-x   2 root root    6 Dec 11  2021 boot
0 drwxr-xr-x   5 root root  340 Jul  2 11:38 dev
0 drwxr-xr-x   1 root root   41 Dec 29  2021 docker-entrypoint.d
4 -rwxrwxr-x   1 root root 1202 Dec 29  2021 docker-entrypoint.sh
0 drwxr-xr-x   1 root root   19 Jul  2 11:38 etc
0 drwxr-xr-x   2 root root    6 Dec 11  2021 home
0 drwxr-xr-x   1 root root   45 Dec 20  2021 lib
0 drwxr-xr-x   2 root root   34 Dec 20  2021 lib64
0 drwxr-xr-x   2 root root    6 Dec 20  2021 media
0 drwxr-xr-x   2 root root    6 Dec 20  2021 mnt
0 drwxr-xr-x   2 root root    6 Dec 20  2021 opt
0 dr-xr-xr-x 264 root root    0 Jul  2 11:38 proc
0 drwx------   2 root root   37 Dec 20  2021 root
0 drwxr-xr-x   1 root root   23 Jul  2 11:38 run
4 drwxr-xr-x   2 root root 4096 Dec 20  2021 sbin
0 drwxr-xr-x   2 root root    6 Dec 20  2021 srv
0 dr-xr-xr-x  13 root root    0 Jul  2 08:16 sys
0 drwxrwxrwt   1 root root    6 Dec 29  2021 tmp
0 drwxr-xr-x   1 root root   66 Dec 20  2021 usr
0 drwxr-xr-x   1 root root   19 Dec 20  2021 var

5.访问nginx服务

http://192.168.1.7:8001/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值