Docker from entry to application (3): Docker common commands
help command
docker version
Display docker version informationdecker info
Display docker system information, including the number of image containersdocker --help
show docker help command
Common mirror commands
-
docker images
List
common parameter descriptions for local mirroring-a
List all mirrors, including hidden intermediate mirrors-q
Show only image ID--no-trunc
Show verbose information without truncating output--digests
show summary
-
docker search <oprions> 镜像名称
Query
the description of common parameters of a mirror--no-trunc
show full image description-f
Query images based on query conditions, common conditionsis-automated
: whether to build automatically,is-official
: whether to be an official image,stars
: number of stars
NAME: image name
DESCRIPTION: image description
STARS: number of likes
OFFICIAL: whether to be an official image
AUTOMATED: whether to automatically build
-
docker pull 镜像名称[:tag]
Download mirror, if no tag is provided, the latest version will be downloaded by default
-
docker rmi -f 镜像名称或者镜像id
Delete image-f
is a mandatory deletion parameter, and the image deletion that has been used needs to be added-f
- Delete a single image
docker rmi -f 镜像名称:TAG或IMAGE ID
- Delete multiple mirrors
docker rmi -f 镜像名1:tag 镜像名2:tag
Separate multiple mirrors with spaces - delete all images
docker rmi -f $(docker images -qa)
- Delete a single image
container command
Containers are built based on mirror images. Containers can only be created with mirror images. Similar to the relationship between classes and objects in Java, objects can only be created with classes.
Docker uses containers to run one or a group of applications independently. A container is a running instance created from an image. It can be started, started, stopped, deleted. Each container is an isolated and secure platform.
The container can be regarded as a simple version of the Linux environment (including root user authority, process space, user space and network space, etc.) and the applications running in it.
The definition of a container is almost the same as that of an image, the only difference is that the top layer of the container is readable and writable.
-
docker run [options] image [command][args]
Create and start the containerDescription of common options
--name
Give the container a new name-d
Important , run the container in the background and return the container id, that is, start the daemon container and
run it in the background, but find that the container has exited. Note: When a Docker container runs in the background, there must be a foreground process . If the command the container runs is not the command that has been suspended (such as top, tail), it will automatically exit.
This is a mechanism problem of docker, such as yours The web container takes Nginx as an example. Under normal circumstances, we only need to start the corresponding service when we configure and start the service, such as service nginx start. However, in doing so, Nginx is already running in the background mode, resulting in no running applications in the docker foreground. The container will kill itself immediately after starting in the background, because docker thinks he has nothing to do, so the best solution is to run the program you want to run as a foreground process.-i
Run the container in interactive mode, typically-t
used with-t
Reassigns a pseudo-input terminal for the container, typically-i
used with-P
capital P , random port mapping-p
The lowercase p specifies the port mapping, which has the following four formats
-ip:hostPort:containerPort
-ip::containerPort
-hostPort:containerPort
-containerPort
port mapping, accessing the local port 8083 can access the corresponding port 8080 of tomcat running in Docker
-
docker ps
View descriptions of common options for all running docker containers
-a
Show running and historically run-l
last running container-n X
of the last X runs, e.g.-n 3
the last three runs-q
Show only the container number
-
exit
close the container and exit -
ctrl+p+q
Exit the container without closing it -
docker start <容器id或容器名>
Start the container -
docker restart <容器id或容器名>
Restart the container -
docker stop <容器id或容器名>
Stop container stop: Slowly stop -
docker kill <容器id或容器名>
Force stop the container -
docker rm <容器id或容器名>
delete stopped container -f force delete (stop first then delete) -
docker rm -f ${docker ps -aq}
ordocker ps-aq|xargs docker -rm
delete all containers -
docker run -d
<container name> daemonized start container -
docker logs -f -t --tail 容器id
Check the container log -t join time -f keep adding ----tail last few lines -
docker top 容器id
View container process -
docker inspect 容器id
View the internal details of the container and display the container information in the form of a json string -
docker exec -it 容器ID bashShell
Enter a running container and interact with the command line
-
docker attach 容器ID
The difference between re-entering the container
docker exec
anddocker attach
attach is to directly enter the terminal of the container startup command, and will not start a new process
exec is to open a new terminal in the container, and can start a new processexec can be understood as entering the container and executing the command, and returning the result, which is more powerful than attach, for example
-
docker cp 容器id:容器内路径 目的主机路径
Copy files from the container to the host docker container id:/container path host path