Docker help_Basic Chapter_Container
- what is a container
-
- list containers docker ps [OPTIONS]
- Start the container docker start container Id or container name
- Enter the container docker exec -it container id (recommended names)
- exit the container exit
- Restart the container docker restart container ID or container name
- Stop container docker stop container ID or container name
- delete container docker rm container id
- Mount the container directory docker run -it -v /host directory:/container directory:ro image name
what is a container
Hi! This is the welcome page that you will display for the first time using the Markdown editor . If you want to learn how to use the Markdown editor, you can read this article carefully to understand the basic syntax of Markdown.
list containers docker ps [OPTIONS]
OPTIONS | illustrate |
---|---|
-a | Shows all containers, including ones that are not running. |
-f | Filter the displayed content based on criteria. |
–format | Template file specifying the return value. |
-l | Shows all containers, including ones that are not running. |
-n | List the n most recently created containers. |
–no-trunc | Do not truncate output. |
-q | In silent mode, only the container number is displayed. |
-s | Displays the total file size. |
docker ps View running containers
docker ps -a View all containers
docker ps -n 2 Show recently created 2 containers
docker ps -f status=exited View stopped containers
Start the container docker start container Id or container name
docker start container ID or container name
Enter the container docker exec -it container id (recommended names)
Docker exec -it container id (names are recommended) followed by ls to see those directories
Docker exec -it container id bash
docker attach container ID or container name
exit the container exit
exit The container stops exiting
ctrl+P+Q The container does not stop exiting
Restart the container docker restart container ID or container name
Stop container docker stop container ID or container name
Violent deletion, kill the process directly (not recommended)
docker kill container ID or container name
delete container docker rm container id
docker rm container ID
If you delete the running container, an error will be reported. If we need to delete it, we need to force it to delete;
force delete docker rm -f container id
Delete multiple containers
docker rm -f container ID1 container ID2 separated by spaces
Remove all containers
docker rm -f $(docker ps -qa)
If you delete a running container, an error will be reported. If we need to delete it, we need to force deletion;
force deletion docker rm -f container ID
delete multiple containers
docker rm -f container ID1 container ID2 separated by spaces
Delete all containers
docker rm - f $(docker ps -qa)
Mount the container directory docker run -it -v /host directory:/container directory:ro image name
Implementation:
docker run -it -v /host directory:/container directory image name
Multi-directory mount
docker run -it -v /host directory:/container directory-v /host directory2:/container directory2 image name
Note:
If you are synchronizing a multi-level directory, there may be a prompt about insufficient permissions;
this is because the security module selinux in Centos7 has disabled permissions, we need to add --privileged=true to solve the problem that the mounted directory has no permissions The problem;
The mount directory is read-only:
docker run -it -v /host directory:/container directory:ro image name
If there is any infringement, please contact by email, I am sorry.
This is only for learning personal notes, and if there is any reprint, please indicate the source.
Contact email: [email protected]
Learn to test the penguin group together (chat, water group, do not disturb advertising): 826471103