Art is long, life is long

Help orders

Docker info displays information about the docker system, including the number of images and containersCopy the code

Documentation: docs.docker.com/engine/refe…

Mirror command

Documentation: docs.docker.com/engine/refe…

Docker Images view images on all local hosts

[root@jiangwang /]# Docker images REPOSITORY TAG IMAGE ID CREATED SIZE Hello - World latest D1165f221234 3 days ago 13.3kB
#explainREPOSITORY REPOSITORY source TAG TAG of the IMAGE IMAGE ID ID of the IMAGE CREATED Time when the IMAGE was CREATED SIZE IMAGE SIZE
#optional-a, --all # list all mirrors -q, Docker images -a REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest D1165f221234 3 days ago 13.3KB [root@jiangwang /]# docker images-q D1165F221234 [root@jiangwang /]# docker images-aq d1165f221234 [root@jiangwang /]#Copy the code

Docker Search searches for images

[root@jiangwang /]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, The open - source base... 10589 [OK] Mariadb Mariadb Server is a high performing sou... 3963 [OK]
#Optional, filter by mirror-f, [root@jiangwang /]# docker search mysql --filter=STARS=3000 NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql mysql is a widely used, open-source relation... 10589 [OK] Mariadb Mariadb Server is a high performing sou... 3963 [OK] [root@jiangwang /]# docker search mysql --filter=STARS=5000 NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation... 10589 [OK] [root@jiangwang /]#Copy the code

Docker pull Downloads the image

docker pull image_name

#Download a mysql image. By default, download the latest image
[root@jiangwang /]# docker pull mysql

#Download the image of the specified version
[root@jiangwang /]# docker pull mysql:5.7

#Take a look at all the images you downloaded[root@jiangwang /]# Docker images REPOSITORY TAG IMAGE ID CREATED SIZE Hello - World latest D1165f221234 3 days ago 13.3kB Mysql 5.7a70d36bc331a 7 weeks ago 449MB mysql latest c8562eaf9d81 7 weeks ago 546MBCopy the code

Remove the mirror

#Delete image docker rmi-f a70d36BC331A based on ID[root@jiangwang /]# docker rmi-f a70d36bc331a Untagged: mysql:5.7 Untagged: mysql@sha256:b3d1eff023f698cd433695c9506171f0d08a8f92a0c8063c1a4d9db9a55808df Deleted: sha256:a70d36bc331a13d297f882d3d63137d24b804f29fa67158c40ad91d5050c39c5 Deleted: sha256:50c77bf7bcddd1f1d97789d80ac2404eec22c860c104e858620d2a2e321f0ef7 Deleted: sha256:14244329b83dfc8982398ee4104a548385652d2bffb957798ff86a419013efd6 Deleted: sha256:6d990477f90af28473eb601a9bca22253f6381e053c5a8edda0a4f027e124a3c Deleted: sha256:ee0449796df204071589162fc16f8d65586312a40c68d1ba156c93c56f5e5ce8 [root@jiangwang /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest d1165f221234 3 days ago 13.3kB mysql latest c8562eaf9d81 7 weeks ago 546MB [root@jiangwang /]#
## Delete all mirrors[root@jiangwang /]# docker rmi -f $(docker images -aq) [root@jiangwang /]# docker images REPOSITORY TAG IMAGE ID CREATED  SIZE [root@jiangwang /]#
#Deleting Multiple MirrorsDocker rmi -f Image ID Image ID Image IDCopy the code

Container command

With the image to create containers, Linux, download a centos image

[root@jiangwang /]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
7a0437f04f83: Pull complete 
Digest: sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[root@jiangwang /]# 
Copy the code

Create a new container and start

Docker run [Optional] image
#Parameters that--name=" name "Container name tomcat01 tomcat02 -p Specified container port -p 8080:8080 -p IP: host port: container port -p Host port: Container port (common) -p Container port Container port -p Randomly specified port
#Test, start, and enter the container
[root@jiangwang /]# docker run -it centos /bin/bash
[root@685c34c813d5 /]# ls   # 查看容器内的centos
bin  etc   lib	  lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr

#Return the host from the container[root@685c34c813d5 /]# exit exit [root@jiangwang /]# ls bin dev home lib lost+found mnt patch root sbin sys usr www boot  etc install.sh lib64 media opt proc run srv tmp varCopy the code

View which containers are currently running

#Docker PS displays containers that are working properly-a # Display current running containers + containers that have been run in history -n=? [root@jiangwang /]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@jiangwang /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 685c34c813d5 centos "/bin/bash" 3  minutes ago Exited (0) About a minute ago pensive_shaw db8909cfa9cc d1165f221234 "/hello" 4 hours ago Exited (0) 4 hours ago adoring_shockley [root@jiangwang /]# docker ps -n=1 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 685c34c813d5 centos "/bin/bash" 7 minutes ago Exited (0) 5 minutes ago pensive_shaw [root@jiangwang /]# docker ps -aq 685c34c813d5 db8909cfa9cc [root@jiangwang /]#Copy the code

Out of the container

[root@jiangwang /]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@jiangwang /]# docker run -it centos /bin/bash [root@589fa10f7998 /]# [root@jiangwang /]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 589fa10f7998 centos "/bin/bash" 31 seconds ago Up 29 seconds magical_noether [root@jiangwang /]#Copy the code

Start, stop, and Restart container commands

Docker start container_name/container_id # Start container_id docker stop container_name/container_id # Stop container_name/container_id # Stop container_name/container_id # Stop container_name/container_id # Container_name /container_id # Restart container docker kill container_name/container_id # Forcibly stop the current containerCopy the code

After starting a container in the background, you can use the attach command to access the container

docker attach container_name/container_id
Copy the code

The command to delete the container

Docker rm container_name/container_id # Cannot delete running containersCopy the code

Delete all stopped containers

docker rm -f $(docker ps -a -q)
Copy the code

View the current system Docker information

docker info
Copy the code

Download an image from the Docker Hub

docker pull centos:latest
Copy the code

Look for nginx images on ocker Hub

docker search nginx
Copy the code

Other commonly used commands

Background startup container

#Docker run -d specifies the image name
[root@jiangwang /]# docker run -d centos
dd83c9017b8b6cb2ed07d1943e0db8421b7ad0864ab291e7d470a6af76a8a6a9
[root@jiangwang /]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@jiangwang /]# 

#Docker ps found centos stopped
#Common pit: Docker container using background running, there must be a foreground process, Docker found no application, automatically stop
#Nginx, once the container is started, it is found that the attack does not provide service, so it stops immediately
Copy the code

See the log

Docker logs -f -t --tail containerCopy the code

View the process information in the container ps

#Docker top Container ID
[root@jiangwang /]# docker top fbff5b668c3a
UID      PID       PPID      C       STIME       TTY           TIME        CMD     
root     4345      4324      0       16:59       pts/0         00:00:00    /bin/bash
Copy the code

View metadata in the mirror

#Docker inspect Container ID
#test[root@jiangwang /]# docker inspect container IDCopy the code

Enter the currently running container

#Command dockerexec-it Container ID /bin/bash

#test[root@jiangwang /]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fbff5b668c3a centos "/bin/bash" 16 minutes ago Up 16 minutes blissful [root@jiangwang /]# docker exec -it fbff5b668c3a /bin/bash [root@fbff5b668c3a /]# ls bin etc lib lost+found mnt proc run srv tmp var dev home lib64 media opt root sbin sys usr [root@fbff5b668c3a /]# ps -ef  UID PID PPID C STIME TTY TIME CMD root 1 0 0 08:59 pts/0 00:00:00 /bin/bash root 16 0 0 09:16 pts/1 00:00:00 /bin/bash root 32 16 0 09:17 pts/1 00:00:00 ps -ef
#Docker Attach container ID
[root@jiangwang /]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
fbff5b668c3a   centos    "/bin/bash"   20 minutes ago   Up 20 minutes             blissful_tu
[root@jiangwang /]# docker attach fbff5b668c3a
[root@fbff5b668c3a /]# ls
bin  etc   lib	  lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr
[root@fbff5b668c3a /]# 
Copy the code

Copy files from a container to a host

#Docker cp Container ID: indicates the host path of the destination in a container
#Into the container[root@jiangwang /]# docker attach fbff5b668c3a [root@fbff5b668c3a /]# ls bin etc lib lost+found mnt proc run srv tmp var  dev home lib64 media opt root sbin sys usr [root@fbff5b668c3a /]# cd home/ #Create a new test.java file under the home path in the container
[root@fbff5b668c3a home]# touch test.java     
[root@fbff5b668c3a home]# ls
test.java
[root@fbff5b668c3a home]# exit
exit
[root@jiangwang /]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
#Copy the test. Java file in the container to the Linux host
[root@jiangwang /]# docker cp fbff5b668c3a:/home/test.java /home    
[root@jiangwang /]# cd home/
#The file is successfully copied to the /home directory
[root@jiangwang home]# ls
f2  f3  jiangwang  test.java  www    
Copy the code