10_光速学会docker用法:80分钟一口气学完docker+k8s!带你掌握docker+k8s所有核心知识点,全程干货,无废话!

启动第一个docker容器 

#1、获取镜像
#2、运行镜像,生成容器,应用就跑在了容器中。

Nginx web服务器,运行处一个80端口的网站

#在宿主机上,运行Nginx
1、开启服务器
2、在服务器上安装好运行Nginx所需的依赖关系
3、安装nginx yum install nginx -y
4、修改ngixnp配置文件
5、启动nginx
6、客户端访问nginx
比较耗时。。。。。。。。。。。

如果让你用docker运行nginx,该怎么玩?

1、获取镜像,获取是从配置好的dcoker镜像网站中,去拉取nginx镜像


#先搜索一下,镜像文件,是否存在
[root@Hadoop2 ~]# docker search nginx
NAME                                              DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
nginx                                             Official build of Nginx.                         18996     [OK]       
unit                                              Official build of NGINX Unit: Universal Web …   12        [OK]       
nginxinc/nginx-unprivileged                       Unprivileged NGINX Dockerfiles                   121                  
nginx/nginx-ingress                               NGINX and  NGINX Plus Ingress Controllers fo…   79                   
nginx/nginx-prometheus-exporter                   NGINX Prometheus Exporter for NGINX and NGIN…   33                   
nginx/unit                                        NGINX Unit is a dynamic web and application …   64                   
nginxinc/nginx-s3-gateway                         Authenticating and caching gateway based on …   2                    
nginx/nginx-ingress-operator                      NGINX Ingress Operator for NGINX and NGINX P…   1                    
nginxinc/amplify-agent                            NGINX Amplify Agent docker repository            1                    
nginx/nginx-quic-qns                              NGINX QUIC interop                               1                    
nginxinc/ingress-demo                             Ingress Demo                                     4                    
nginxproxy/nginx-proxy                            Automated Nginx reverse proxy for docker con…   103                  
nginxproxy/acme-companion                         Automated ACME SSL certificate generation fo…   123                  
bitnami/nginx                                     Bitnami nginx Docker Image                       173                  [OK]
bitnami/nginx-ingress-controller                  Bitnami Docker Image for NGINX Ingress Contr…   29                   [OK]
ubuntu/nginx                                      Nginx, a high-performance reverse proxy & we…   98                   
nginxinc/nginmesh_proxy_debug                                                                      0                    
nginxproxy/docker-gen                             Generate files from docker container meta-da…   12                   
nginxinc/mra-fakes3                                                                                0                    
kasmweb/nginx                                     An Nginx image based off nginx:alpine and in…   6                    
rancher/nginx-ingress-controller                                                                   11                   
nginxinc/ngx-rust-tool                                                                             0                    
nginxinc/mra_python_base                                                                           0                    
nginxinc/nginmesh_proxy_init                                                                       0                    
rancher/nginx-ingress-controller-defaultbackend                                                    2                    
[root@Hadoop2 ~]# 


#拉取,下载镜像
[root@Hadoop2 ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
360eba32fa65: Pull complete 
c5903f3678a7: Pull complete 
27e923fb52d3: Pull complete 
72de7d1ce3a4: Pull complete 
94f34d60e454: Pull complete 
e42dcfe1730b: Pull complete 
907d1bb4e931: Pull complete 
Digest: sha256:6926dd802f40e5e7257fded83e0d8030039642e4e10c4a98a6478e9c6fe06153
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@Hadoop2 ~]# 

#查看本地的docker镜像有那些
[root@Hadoop2 ~]# docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
nginx        latest    f5a6b296b8a2   5 days ago   187MB
[root@Hadoop2 ~]# 


#删除镜像的命令,其中使用了IMAGE ID,镜像ID;
docker rmi f5a6b296b8a2

#运行该nginx镜像,运行出具体的容器,然后这个容器中就可以跑一个nginx服务了;
#运行镜像的命令,参数如下
docker run  参数 镜像的名字/ID

# -d后台运行容器
# -p 80:80 端口映射,宿主机端口:容器内端口。若访问宿主机某个端口,相应的就会访问容器中对应端口。
docker run -d -p 80:80 nginx

#运行结果如下,docker run命令,会返回一个容器的id
[root@Hadoop2 ~]# docker run -d -p 80:80 nginx
00d67544a8726e38459036279a1c68839ec82f47fa3d49d95fb5cdd7b806239c
[root@Hadoop2 ~]# 

#查看容器是否在运行
[root@Hadoop2 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                   CREATED              STATUS              PORTS                               NAMES
00d67544a872   nginx     "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, :::80->80/tcp   great_mayer
[root@Hadoop2 ~]# 

#可以尝试停止容器,看下结果
docker stop 容器ID

#停止具体的容器进程
[root@Hadoop2 ~]# docker stop 00d67544a872
00d67544a872
[root@Hadoop2 ~]# 

#查看看存在的进程
[root@Hadoop2 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@Hadoop2 ~]# 


docker stop 


 

 查看端口占用情况

[root@Hadoop2 ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      798/rpcbind         
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2097/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1211/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1209/cupsd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1403/master         
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      2144/sshd: root@pts 
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN      6197/sshd: root@pts 
tcp6       0      0 :::111                  :::*                    LISTEN      798/rpcbind         
tcp6       0      0 :::22                   :::*                    LISTEN      1211/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1209/cupsd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1403/master         
tcp6       0      0 ::1:6010                :::*                    LISTEN      2144/sshd: root@pts 
tcp6       0      0 ::1:6011                :::*                    LISTEN      6197/sshd: root@pts 
udp        0      0 192.168.122.1:53        0.0.0.0:*                           2097/dnsmasq        
udp        0      0 0.0.0.0:67              0.0.0.0:*                           2097/dnsmasq        
udp        0      0 0.0.0.0:68              0.0.0.0:*                           6198/dhclient       
udp        0      0 0.0.0.0:111             0.0.0.0:*                           798/rpcbind         
udp        0      0 127.0.0.1:323           0.0.0.0:*                           818/chronyd         
udp        0      0 0.0.0.0:972             0.0.0.0:*                           798/rpcbind         
udp        0      0 0.0.0.0:33872           0.0.0.0:*                           809/avahi-daemon: r 
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           809/avahi-daemon: r 
udp6       0      0 :::111                  :::*                                798/rpcbind         
udp6       0      0 ::1:323                 :::*                                818/chronyd         
udp6       0      0 :::972                  :::*                                798/rpcbind         
[root@Hadoop2 ~]# 





运行后
[root@Hadoop2 ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      798/rpcbind         
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6464/docker-proxy   
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2097/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1211/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1209/cupsd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1403/master         
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      2144/sshd: root@pts 
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN      6197/sshd: root@pts 
tcp6       0      0 :::111                  :::*                    LISTEN      798/rpcbind         
tcp6       0      0 :::80                   :::*                    LISTEN      6471/docker-proxy   
tcp6       0      0 :::22                   :::*                    LISTEN      1211/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1209/cupsd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1403/master         
tcp6       0      0 ::1:6010                :::*                    LISTEN      2144/sshd: root@pts 
tcp6       0      0 ::1:6011                :::*                    LISTEN      6197/sshd: root@pts 
udp        0      0 192.168.122.1:53        0.0.0.0:*                           2097/dnsmasq        
udp        0      0 0.0.0.0:67              0.0.0.0:*                           2097/dnsmasq        
udp        0      0 0.0.0.0:68              0.0.0.0:*                           6198/dhclient       
udp        0      0 0.0.0.0:111             0.0.0.0:*                           798/rpcbind         
udp        0      0 127.0.0.1:323           0.0.0.0:*                           818/chronyd         
udp        0      0 0.0.0.0:972             0.0.0.0:*                           798/rpcbind         
udp        0      0 0.0.0.0:33872           0.0.0.0:*                           809/avahi-daemon: r 
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           809/avahi-daemon: r 
udp6       0      0 :::111                  :::*                                798/rpcbind         
udp6       0      0 ::1:323                 :::*                                818/chronyd         
udp6       0      0 :::972                  :::*                                798/rpcbind         
[root@Hadoop2 ~]# 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值