Notes from: https://pan.baidu.com/s/1FLcOpjpJTJlP36lzD-kfWA#list/path=%2F
Help command
docker version
docker info
docker --help
Mirror command
docker images
List the mirrors on the local host
Description of each option:
REPOSITORY | Indicates the source of the mirrored warehouse |
TAG | Mirrored label |
IMAGE ID | Mirror ID |
CREATED | Mirror creation time |
SIZE | Mirror size |
options description
-a: List all local mirrors (including the intermediate image layer)
-q: only display mirror id
--digests: Display summary information of the mirror
--no-trunc: display complete mirror information
docker search the name of a certain image
options:
--no-trunc: show the complete mirror description
-s: List the mirrors whose collection number is not less than the specified value
-automated: Only list images of the automated build type
docker pull the name of a certain image
Download mirror
docker pull image name[:TAG]
docker rmi a certain image name id
Delete mirror
Delete a single-docker rmi -f mirror id
Delete multiple-docker rmi -f Mirror name 1: TAG Mirror name 2: TAG
Delete all-docker rmi -f $(docker images -qa)
Container command
Only an image can create a container, which is the fundamental premise
docker pull centos
Create and start the container docker run [options] image [command] [arg..]
options
OPTIONS description (commonly used): some are a minus sign, some are two minus signs
--name="Container new name": Specify a name for the container;
-d: Run the container in the background and return the container ID, that is, start the daemon container;
-i: Run the container in interactive mode, usually used with -t;
-t: reassign a pseudo input terminal for the container, usually used with -i;
-P: random port mapping;
-p: Specify port mapping, there are the following four formats
ip:hostPort:containerPort
ip::containerPort
hostPort:containerPort
containerPort
Start interactive container
#Use mirror centos:latest to start a container in interactive mode and execute the /bin/bash command in the container.
docker run -it centos /bin/bash
List currently running containers
docker ps [options]
-a: lists all currently running container + run-off in the history of
-l: Display the recently created container.
-n: Display the last n created containers.
-q: Silent mode, only the container number is displayed.
--no-trunc: Do not truncate the output.
Exit the container
exit: The container stops exiting
ctrl+p+q container does not stop and exit
Start the container
docker start container id or container name
Restart container
docker restart container id or container name
Stop container
docker stop container id or container name
Forcibly stop the container
docker kill container id or container name
Delete the stopped container
docker rm container id
Delete multiple containers at once: docker rm -f $(docker ps -a -q) docker ps -a -q|xargs docker rm
Start the daemon container
docker run -d container name
Use the mirror centos:latest to start a container in background mode
docker run -d centos
Question: After checking docker ps -a, you will find that the container has exited
An important point to note: Docker container running in the background must have a foreground process.
If the commands run by the container are not those that have been suspended (such as running top, tail), they will automatically exit.
This is the mechanism of docker. For example, for your web container, we take nginx as an example. Under normal circumstances, we only need to start the responding service if we configure to start the service. E.g
service nginx start
However, in doing so, nginx runs in background process mode, which results in applications that are not running in the docker foreground.
After such a container is started in the background, it will immediately commit suicide because he thinks he has nothing to do.
Therefore, the best solution is to run the program you want to run as a foreground process
View container logs
docker logs -f -t --tail 容器id
-t is to add timestamp
-f follow the latest log print
--tail number shows how many last there are
View the processes running in the container
docker top container id
View the internal details of the container
docker inspect container id
Enter the running container and interact with the command line
docker exec -it 容器id bashShell
Re-enter the docker attach container id
The difference between the two: attach directly into the terminal of the container start command, and will not start a new thread. exec opens a new terminal in the container and can start a new thread.
Copy files from the container to the host
docker cp container id: the destination host path of the path in the container
to sum up: