This article only makes simple records. For details of the docker command, please refer to the official document: https://docs.docker.com/reference/;
command | necessary parameters | Commonly used optional parameters | command description |
---|---|---|---|
exit | Exit in the Yinger | ||
docker attach | [container ID] | Enter the existing terminal in the container, and will not open a new terminal | |
docker commit | [container ID] Mirror name: label | -a -m |
# Author # Mirror description |
docker cp | [container ID]: file path host path | file copy in the container | |
docker exec | -it [container ID] | Enter Docker with new terminals | |
docker info | Query Docker system information, including mirrors and containers | ||
docker images | -a -q |
Display all mirror images (the same when it is not with) Only display mirror ID |
|
docker inspect | [container ID] | # container information view | |
docker kill | [container ID] | Force stopped container | |
docker logs | [container ID] | -f -n, –tail -t |
# 2 2 2 2 # output log line number # Log output includes time |
docker pull | image | download mirror | |
docker ps | -a -n=? -l -q -s |
# Query all containers, including historical running # List the recently created n container # List the recently created container # List the label of the container # display container size |
|
docker rmi | mirror ID | -f | Forced delete mirror |
docker rm | [container ID] | -f | Forced delete container |
docker run | image | –name=“Name” -d -it -p -P |
# Specify the name of the container, the default is the mirror when the name of the container is not specified # Specify the container background to run # Specify the interactive method to run, and enter the container to view the content # specified container port -P 8080: 8080 host port: container port # Random specified port |
docker restart | [container ID] | Restart container | |
docker start | [container ID] | 4 4 | |
docker stats | View docker container operation resource consumption situation | ||
docker stop | [container ID] | Stop the container | |
docker search | image | -f | Mirror search command |
docker top | container ID | View process in the container | |
docker -v | docker version | Query Docker version information |
docker -v # o docker version information
docker version # o Docker version information
docker info # o Docker system information, including mirror and container quantity
dockerCommand -Help# command help
docker imagesQuery mirror in docker
[[email protected] /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 10 months ago 13.3kB
# command operating parameter item:
--all , -a # Display all mirror images (when not with it)
--quiet,-q # Only display mirror ID
docker searchMirror search command
# command operating parameter item:
--filter , -f Filter output based on conditions provided
# The results of STARS above 4000 in query results
[[email protected] /]# docker search mysql -f stars=4000
[[email protected] /]# docker search mysql --filter=STARS=4000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 12923 [OK]
mariadb MariaDB Server is a high performing open sou… 4954 [OK]
docker pulldownload command
docker pull mysql # 6 6 6 6 6 6 6
docker pull mysql:5.7 # Combination: TAG tag pulls the corresponding version of the image
# 介绍 6 6 Introduction
[[email protected] /]# docker pull mysql
Using default tag: latest # Pulling version
latest: Pulling from library/mysql
72a69066d2fe: Pull complete # layered download file
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
688ba7d5c01a: Pull complete
00e060b6d11d: Pull complete
1c04857f594f: Pull complete
4d7cfa90e6ea: Pull complete
e0431212d27d: Pull complete
Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709 # signature
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest # real address
docker7 After exit, restart
SystemCTL Start Docker.service
orsudo service docker restart
# Restart network service
systemctl restart network && systemctl restart docker
docker rmiDelete mirror
dockerRMI -F mirror ID# Delete a mirror
dockerRMI -F mirror ID image ID image ID# Delete multiple images
docker rmi -f $(docker images -aq) # Delete all mirrors
container creation requires the corresponding container, throughdocker pull
Operation pulls the corresponding mirror.
docker run [Optional parameter] image
# Common parameter description:
--name="Name" # Specify the name of the container, the default is the mirror when the name of the container is not specified
-d # Specify the container background to run
-it # 8 8 8 8 8, and enter the container to view the content
-p # Specify container port -P 8080: 8080 Host port: container port-P host port: container port#*Commonly used*-P container port
Container
-P# Random specified port
# Example:
# /bin /bash IT operating method specified interactive controller
[[email protected] ~]# docker run -it centos /bin/bash
[[email protected] /]# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[[email protected] /]# Exit # Exit container
exit
Note: -D when starting the container in the background, you need to pay attention. If the docker starts, it is easy to run without the front desk program.
# Background startup container /bin /bash similar service to the front desk -C is the script behind
docker run -d centos /bin/bash -c "while true; do echo docker run test ; sleep 1 ; done"
1e274e49713ead723824722b8539a3639432fc119e1a03021fe70a39f015b4d3
[[email protected] /]# docker ps -a
CONTAINER ID IMAGE
1e274e49713e centos
docker ps [parameter] # When there is no parameter, only list the running container
# Common parameter description:
-a # Query all containers, including historical running
-n=? # List the recently created n container
-l # List the recently created container
-q # List the label of the container
-s # display container size
# ---------------------------------------------------------------------------------
exit # Exit and stop the container
Ctrl+P+Q # shortcut key exit without stopping the container
# ----------- -d background mode container -------------
exit # Exit will not stop the container
docker rm [container ID] # Can't delete the container that is running
docker rm -f [container ID] # Forced deletion
docker rm -f $(docker ps -aq) # All container for compulsory deletion
docker ps -a -q|xargs docker rm # Delete all containers
docker start [container ID] # 12 12
docker restart [container ID] # Restart container
docker stop [container ID] # Stop the container
docker kill [container ID] # Forced stop
# parameter description
-f # 12 12 12 12
-n, --tail string # output log line number
-t, --timestamps # Log output includes time
# Example
[[email protected] /]# docker logs -f -n=3 1e274e49713e
docker run test
docker run test
docker run test
^C
[[email protected] /]# docker logs -f -t -n=3 1e274e49713e
2022-07-28T07:59:11.652065801Z docker run test
2022-07-28T07:59:12.656388498Z docker run test
2022-07-28T07:59:13.660228343Z docker run test
# Method 1: Docker Exec enters Docker with new terminals
docker exec -it [container ID] /bin/bash
# Method 2: Docker Attach enters the existing terminals in the container, and will not open a new terminal
docker attach [container ID]
docker top [container ID] # container process view
docker inspect [container ID] # container information view
docker cp [container ID]: File path host path# Copy in the container to the host
dockerCOMMIT parameters[container ID]Mirror name: Tag# Submit the container to a new image
# parameter description
-a, --author string # Author
-m, --message string # mirror description
-p, --pause # During the submission period, the container is suspended, and the default TRUE
# Example:
[[email protected] ~]# docker commit -a="sr" -m="cp resource root.." 1d9b8d00b3c1 tomcat_sr:1.0
sha256:2c03f4ad3dcaaf4ef50978b0e1585b36e25589963e4c5b156e0860f6cc5e7cfc
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat_sr 1.0 2c03f4ad3dca 7 seconds ago 684MB
tomcat latest fb5657adc892 7 months ago 680MB