Docker related command application

  Docker commands   

  • -a stdin:  Specify the content type of standard input and output, and three items of STDIN/STDOUT/STDERR are optional;

  • -d:  run the container in the background and return the container ID;

  • -i:  run the container in interactive mode, usually used with -t;

  • -t:  reallocate a pseudo input terminal for the container, usually used at the same time as -i;

  • --name="nginx-lb":  Specify a name for the container;

  • --dns 8.8.8.8:  Specify the DNS server used by the container, the default is the same as the host;

  • --dns-search example.com:  Specify the container DNS search domain name, the default is the same as the host;

  • -h "mars":  specifies the hostname of the container;

  • -e username="ritchie":  set environment variables;

  • --env-file=[]:  Read environment variables from the specified file;

  • --cpuset="0-2" or --cpuset="0,1,2":  Bind the container to the specified CPU to run;

  • -m : Set the maximum memory used by the container;

  • --net="bridge":  Specify the network connection type of the container, support bridge/host/none/container: four types;

  • --link=[]:  add a link to another container;

  • --expose=[]:  open a port or a group of ports; 

1. Docker common commands to explain the process

docker images   View local mirror warehouse

docker rmi [image id]   delete the image in the local image repository. The image id is the image ID that needs to be deleted

docker pull [image name]:[tag]   Download the image to the local image repository, image name image name, tag image version

docker search [keyword]    View the content of the local image. The keyword is the keyword of the image name. You do not need to enter all the image names.

docker run -d [image]     executes the image into a virtual environment

docker build -t [image name] .

docker build -t [image name] -f [dockerfile] .

docker tag [original image name] [new image name]

docker tag [original image name]:[tag] [new image name]:[tag]

docker run -it [image] bash     executes the image into a virtual environment and directly enters the docker virtual environment (equivalent to docker exec -it [image] bash)

docker exec -it [image] bash    executes the image into a virtual environment and directly enters the docker virtual environment

docker run -d -p 8080:80 nginx   accesses the external iP port is 8080. In fact, the 80 port corresponding to the internal ip executes the nginx action

docker run -dv /data:/data nginx   mounts the data of the server to the data inside docker so that it can be used inside docker.

docker run -d -e MYENV=test nginx   changes the environment variable of the server to the environment inside docker.

docker network create mynet1  creates a network card named mynet1

docker ps       to view the container container of the docker in execution,

docker ps -p      -p only displays the id number of the container being executed 

docker ps -a      -a shows all containers, both stopped and running

docker start [instance-id]   starts the instance, instance-id instance ID number

docker stop  [instance-id]   stops the instance, instance-id instance ID number

docker attach [instance-id]   makes the actions of the two windows consistent 

docker rm [instance-id]    delete the running instance instance, you need to stop the instance before deleting

docker rm -f [instance-id]   Force delete the running instance instance, you can delete the instance directly without stopping the instance

docker rm -f `docker ps -q`  deletes all executing containers, ``calls the execution result as the parameter of the previous delete operation.

[example]

[root@docker ~]#  docker ps View running container

CONTAINER ID    IMAGE       COMMAND          CREATED        STATUS        PORTS           NAMES

378e85b45f67    nginx     "nginx -g 'daemon of  28 minutes ago     Up 28 minutes    80/tcp        clever_turing    

7fad893a54c4    nginx     "nginx -g 'daemon of   29 minutes ago    Up 29 minutes   0.0.0.0:8080->80/tcp   thirsty_yonath   

[root@docker ~]#  docker rm -f `docker ps -q ` delete all running containers

378e85b45f67

7fad893a54c4

[root@docker ~]#  docker ps View the container being executed, all of which have been deleted

CONTAINER ID    IMAGE       COMMAND      CREATED      STATUS       PORTS         NAMES

[root@docker ~]# docker ps -a -q View all containers, whether they are being executed or deleted, -q only shows instance-id

bebf3f5b8112

0577c4b78979

1d26ba3448f0

3e05321bdbca

4cb7712e3dd7

[root@docker ~]#  docker rm -f `docker ps -q -a ` Force delete all containers, whether they are stopped or running.

bebf3f5b8112

0577c4b78979

1d26ba3448f0

3e05321bdbca

4cb7712e3dd7

[root@docker ~]# docker ps -a -q Check again that there is no container, and it has been deleted.

2 . Command format:

docker run -it --name mydocker1 [image1] bash  # Alias ​​image1 as mydocker1

docker run -it --link mydocker1:mydocker1 [image2] bash   connects the two images so that image1 and image2 can communicate with each other

3 . Command function:

Connect two containers to communicate with each other

3 . Command parameters:

-it --name Name the first image1 first

-it --link connect to the first image and communicate with each other


5 . Command example:

Example 1

First open a window and enter the following command to open a docker window 1

  [root@docker ~]# docker run -it --name node1 node bash

root@f2765d5fd9c8:/# 

再次打开另一个窗口2,输入以下命令:

[root@docker ~]# docker run -it --link node1:node1 node bash

root@e85d11098482:/# 

在第二个docker窗口下输入以下命令:

root@e85d11098482:/# ping node1  显示node1的ip地址是172.16.0.16

PING node1 (172.17.0.16): 56 data bytes

64 bytes from 172.17.0.16: icmp_seq=0 ttl=64 time=0.110 ms

64 bytes from 172.17.0.16: icmp_seq=1 ttl=64 time=0.073 ms

64 bytes from 172.17.0.16: icmp_seq=2 ttl=64 time=0.075 ms

64 bytes from 172.17.0.16: icmp_seq=3 ttl=64 time=0.094 ms

^C--- node1 ping statistics ---

4 packets transmitted, 4 packets received, 0% packet loss

round-trip min/avg/max/stddev = 0.073/0.088/0.110/0.000 ms

在第一个docker窗口下输入以下命令,查看该窗口的IP地址正是node1的IP地址

root@f2765d5fd9c8:/# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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

34: eth0@if35: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 

    link/ether 02:42:ac:11:00:10 brd ff:ff:ff:ff:ff:ff

    inet 172.17.0.16/16 scope global eth0

       valid_lft forever preferred_lft forever

    inet6 fe80::42:acff:fe11:10/64 scope link 

       valid_lft forever preferred_lft forever


实例二

attach实例,通过attach使得两个窗口显示一模一样:

[root@docker docker]# docker run -it nginx bash 

root@0f8a31139121:/# ls

bin  boot  devetc  home  liblib64  media  mnt  optproc  root  run  sbin  srv  sys  tmp  u

root@0f8a31139121:/# 

[root@docker ~]# docker ps  -q  先查看正在运行的docker进程

0f8a31139121

[root@docker ~]# docker attach 0f8a31139121 

ls

bin  boot  devetc  home  liblib64  media  mnt  optproc  root  run  sbin  srv  sys  tmp  u

root@0f8a31139121:/# 


实例三:

docker network create mynet1实例:

[root@docker docker]#docker network create mynet2  建立网卡,命名为mynet2

Error response from daemon: network with name mynet2 already exists   #提示该名称的网卡已存在

[root@docker docker]# docker network create mynet1

647cb9fd3d7162da73aaf12eba4dbcd88b7c0790f6eda617f6635b5c4eb13f7e

[root@docker docker]# docker network create mynet3

aa6f9827251c45cd88f308108bd78bb6ef719ed04d37213277217c95b615f17c

[root@docker docker]# docker run -d --name c1 --net mynet1 nginx  打开nginx,并命名为c1,且设定网卡为mynet1刚建立的网卡

b772bb24c6457d6c0528a16d3820841f06d934a10809dd266862687222344134

[root@docker docker]#  docker run -d --name c2 --net mynet2 nginx

66221df665551e658a81e169611d32179d119fc17b684a6ba9bca1b16b2a5b3f

[root@docker docker]#  docker run -d --name c3 nginx  打开nginx程序,并命名为c3,但不指定网卡。

54fc6b30e9838f0e261ba82562de5a2a00e07667b46baf2f8f6f701107f80251

[root@docker docker]#  docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES

54fc6b30e983        nginx               "nginx -g 'daemon off"   3 seconds ago       Up 2 seconds        80/tcp              c3

66221df66555        nginx               "nginx -g 'daemon off"   19 seconds ago      Up 18 seconds       80/tcp              c2

b772bb24c645        nginx               "nginx -g 'daemon off"   28 seconds ago      Up 27 seconds       80/tcp              c1

[root@docker docker]# docker exec -it c1 bash  #直接进入刚才建立的c1 bash

root@b772bb24c645:/# 


实例四:

[root@docker docker]#docker rm -f `docker ps -q -a`

54fc6b30e983

66221df66555

b772bb24c645

[root@docker docker]# docker run -d -p 5000:5000 --name registry registry:2

Unable to find image 'registry:2' locally

2: Pulling from library/registry

9f9a7687cb91: Pull complete 

607d8cb26263: Pull complete 

305c4b3247bc: Pull complete 

09fd65a9f827: Pull complete 

5614c459bd0f: Pull complete 

7d72978aa116: Pull complete 

5a7694fedddd: Pull complete 

37213f6a1a3f: Pull complete 

6bb73e9857ff: Pull complete 

8fe0c76b17fc: Pull complete 

Digest: sha256:6cd209f81e188e8eaa13fad9b670fb1a4e9c7776a73b3881b69834fe5ddfb193

Status: Downloaded newer image for registry:2

c88ae6df9e41f06dbfc283585269ed7df0e23621b2357d2e3b73622565512048

[root@docker docker]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED           STATUS                PORTS                        NAMES

c88ae6df9e41       registry:2       "/entrypoint.sh /etc/"   10 seconds ago     Up 8 seconds   0.0.0.0:5000->5000/tcp   registry

[root@docker docker]# docker images

REPOSITORY          TAG             IMAGE ID            CREATED             VIRTUAL SIZE

nginx               latest              e076c61a6bf2        2 weeks ago         108.9 MB

node                latest              46ecedfa82d3        2 weeks ago         672.8 MB

registry            2                   8fe0c76b17fc        3 months ago        33.26 MB

[root@docker docker]# docker tag nginx localhost:5000/nginx

[root@docker docker]# docker images

REPOSITORY             TAG               IMAGE ID            CREATED             VIRTUAL SIZE

localhost:5000/nginx   latest        e076c61a6bf2        2 weeks ago         108.9 MB

nginx                  latest              e076c61a6bf2        2 weeks ago         108.9 MB

node                   latest              46ecedfa82d3        2 weeks ago         672.8 MB

registry               2                   8fe0c76b17fc        3 months ago        33.26 MB

[root@docker docker]# docker push localhost:5000/nginx 

The push refers to a repository [localhost:5000/nginx] (len: 1)

e076c61a6bf2: Pushed 

235c9b4b2c82: Pushed 

8bc1215bde0f: Pushed 

abc60fac2aea: Pushed 

latest: digest: sha256:9a032ad6687bd8a621c6d7dbd29163eff9c35d5e77c04ddef9da52c63c72a934 size: 9566



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324601682&siteId=291194637