The basic operation of the container docker

Transfer: https://mp.weixin.qq.com/s?__biz=MzU3NzczMTAzMg==&mid=2247484229&idx=1&sn=8693293c3ad09b97b7647804e8cbf692&chksm=fd0163f2ca76eae48b32389523671c26f1710350bd09ca943abbb94718604c2083e823383a34&scene=21#wechat_redirect

 

docker View all current container

docker ps -a

[root@izr86 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS               NAMES
1ccd3d443198        hello-world         "/hello"            43 hours ago        Exited (0) 43 hours ago                       elated_lamarr
256192dc46e4        hello-world         "/hello"            2 days ago          Exited (0) 2 days ago                         great_gould
[root@izr86 ~]# 

docker view the newly created container

docker ps -l

[root@izr86 ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS               NAMES
1ccd3d443198        hello-world         "/hello"            43 hours ago        Exited (0) 43 hours ago                       elated_lamarr
[root@izr86 ~]# 

Create a container:

docker create nginx (name of the container)

Container at this time is to stop the creation of the state, not running

[root@izr86 ~]# docker create nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
8d691f585fa8: Pull complete 
5b07f4e08ad0: Pull complete 
abc291867bca: Pull complete 
Digest: sha256:922c815aa4df050d4df476e92daed4231f466acc8ee90e0e774951b0fd7195a4
Status: Downloaded newer image for nginx:latest
154847240dc658655e9d5bb496eeca837fe0e9a5d4561c16833bfcb6b4f71673
[root@izr86 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                    PORTS               NAMES
154847240dc6        nginx               "nginx -g 'daemon of…"   7 seconds ago       Created                                       determined_moore
1ccd3d443198        hello-world         "/hello"                 43 hours ago        Exited (0) 43 hours ago                       elated_lamarr
256192dc46e4        hello-world         "/hello"                 2 days ago          Exited (0) 2 days ago                         great_gould
[root@izr86 ~]# 

Delete container

Before deleting vessel to stop running

To see the first container to be removed is running

docker ps to view the currently running container

[root@izr86 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

After viewing the current container, we remove a container

256192dc46e4        hello-world         "/hello"                 2 days ago          Exited (0) 2 days ago                         great_gould
[root@izr86 ~]# docker rm 256192dc46e4
256192dc46e4

You can delete a container vessel according to id, or delete a name according to id

docker start container

docker start container name / id

[root@izr86 ~]# docker ps -l
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                          PORTS               NAMES
39ab25ad95fa        nginx               "nginx -g 'daemon of…"   15 minutes ago      Exited (0) About a minute ago                       nginx1
[root@izr86 ~]# docker start nginx1
nginx1

 

running off the container docker

docker stop container name / id

[root@izr86 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                          NAMES
39ab25ad95fa        nginx               "nginx -g 'daemon of…"   10 minutes ago      Up 10 minutes       80/tcp, 0.0.0.0:8090->90/tcp   nginx1
[root@izr86 ~]# docker stop 39ab25ad95fa
39ab25ad95fa

 docker run a container

docker run -d -p 8090:90 

-d represents a container in the background, -p shows a map of container port 80 to port 8080 of the host,

[root@izr86 ~]# docker run -d -p 8090:90 nginx
cf781e80699b3d3c044a469ef0db63e971eb2cc84bcc1a94004e98e61166eb77
[root@izr86 ~]# netstat -ntpl
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:80              0.0.0.0:*               LISTEN      30041/java          
tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN      2972/epmd           
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1398/sshd           
tcp        0      0 0.0.0.0:15672           0.0.0.0:*               LISTEN      32423/beam          
tcp        0      0 127.0.0.1:8005          0.0.0.0:*               LISTEN      30041/java          
tcp        0      0 0.0.0.0:25672           0.0.0.0:*               LISTEN      32423/beam          
tcp        0      0 0.0.0.0:8009            0.0.0.0:*               LISTEN      30041/java          
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      6457/svnserve       
tcp6       0      0 :::4369                 :::*                    LISTEN      2972/epmd           
tcp6       0      0 :::8090                 :::*                    LISTEN      6226/docker-proxy   
tcp6       0      0 :::5672                 :::*                    LISTEN      32423/beam          
tcp6       0      0 :::3306                 :::*                    LISTEN      12963/mysqld        
[root@izr86 ~]# 

But now we can not outside the network 8090, or the access barrier

Because we are bound to port 90 docker, we must bind docker port 80 can be accessed via the external network

[root@izr86o15kikb3az ~]# docker run -d -p 8090:80 nginx
88cde77f1b79daa5b4de88be6be081b109f38dd136ad3d1c476894e3c7b22a43

Basis of the above described docker, and some basic applications

 

I hope for your help


 

 

 

Published 356 original articles · won praise 147 · views 760 000 +

Guess you like

Origin blog.csdn.net/datouniao1/article/details/102736224