Docker container information
View docker container version
docker version
View docker container information
docker info
View docker container help
docker --help
Mirror operation
Mirror view
List local images
docker images
Including intermediate image layer
docker images -a
Only the mirror ID is displayed
docker images -q
Including intermediate image layer
docker images -qa
Displays the mirror summary information (the DIGEST column)
docker images --digests
Displays the full image information
docker images --no-trunc
Displays the creation history of the specified image; Parameters: - H image size and date; the default is true-- no-trunc Display complete submission records- q Only submit record ID s are listed
docker history -H redis
Mirror search
Search warehouse MySQL image
docker search mysql
--filter=stars=600: only images with starts > = 600 are displayed
docker search --filter=stars=600 mysql
-- No TRUNC displays the full DESCRIPTION of the image
docker search --no-trunc mysql
--Automated: only images with AUTOMATED=OK are listed
docker search --automated mysql
Image download
Download the latest official Redis image, which is equivalent to docker pull redis:latest
docker pull redis
Download all Redis images in the warehouse
docker pull -a redis
Download private warehouse image
docker pull bitnami/redis
Mirror deletion
Deleting a single image is equivalent to: docker rmi redis:latest
docker rmi redis
Force deletion (for image-based container processes that are running)
docker rmi -f redis
Multiple images are deleted, and different images are separated by spaces
docker rmi -f redis tomcat nginx
Delete all local mirrors
docker rmi -f $(docker images -q)
Mirror construction
Write dockerfile
cd /docker/dockerfile vim mycentos
Build docker image
docker build -f /docker/dockerfile/mycentos -t mycentos:1.1
Container operation
Tip: for container operations, you can use CONTAINER ID or NAMES.
Container start
Create a new container and start it. Parameters:
-i Run the container in interactive mode;
-t Reassigning a pseudo input terminal to the container;
--name Specify a name for the container
docker run -i -t --name mycentos
Background start container, parameter: - d Container started in daemon mode
docker run -d mycentos
Note: use "docker ps -a" to find that the container has exited. This is the docker mechanism: to make the docker container run in the background, there must be a foreground process. Solution: run the program you want to run as a previous process.
Start one or more containers that have been stopped
docker start redis
Restart container
docker restart redis
Container process
Top supports ps command parameters. Format: docker top [OPTIONS] CONTAINER [ps OPTIONS]
Lists the processes running in the redis container
docker top redis
View the process information of all running containers
for i in `docker ps |grep Up|awk '{print $1}'`; do echo \ &&docker top $i; done
View redis container logs. Default parameters
docker logs rabbitmq
View redis container log, parameter: - f Trace log output- t Display timestamp-- tail Only the latest N container logs are listed;
docker logs -f -t --tail=20 redis
View the latest 10 logs of container redis since May 21, 2019.
docker logs --since="2019-05-21" --tail=10 redis
Entry and exit of containers
Use the run method to enter when creating
docker run -it centos /bin/bash
Close the container and exit
exit
Only exit the container without closing it
Shortcut keys: Ctrl + P + Q
Directly enter the terminal of centos container startup command without starting a new process. Multiple attach connections share the container screen. Parameters: - sig proxy = false Make sure CTRL-D or CTRL-C does not close the container
docker attach --sig-proxy=false centos
Open a new interactive mode terminal in centos container to start a new process. Parameters: - i Keep STDIN open even if there is no additional- t Assign a pseudo terminal
docker exec -i -t centos /bin/bash
Execute the command in the container in interactive mode, and the result returns to the current terminal screen
docker exec -i -t centos ls -l /tmp
Execute commands in the container in separate mode, the program runs in the background, and the results will not be fed back to the current terminal
docker exec -d centos touch cache.txt
View container
View running containers
docker ps
View the ID of the running container
docker ps -q
View running + historically running containers
docker ps -a
Displays the total file size of the running container
docker ps -s
Displays recently created containers
docker ps -l
Displays the 3 recently created containers
docker ps -n 3
Do not truncate output
docker ps --no-trunc
Get the meta information of the image redis
docker inspect redis
Get the IP address of the running redis container
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redis
Stopping and deleting containers
Stop a running container
docker stop redis
Kill a running container
docker kill redis
Delete a stopped container
docker rm redis
Delete a running container
docker rm -f redis
Delete multiple containers
docker rm -f $(docker ps -a -q)
docker ps -a -q | xargs docker rm
-l remove the network connection between containers. The connection name is db
docker rm -l db
-v delete the container and delete the data volumes mounted by the container
Generate image
Create a new image based on the current redis container;
Parameters:
-a the author of the submitted image;
-c use the Dockerfile instruction to create an image;
-m: description at the time of submission;
-p: pause the container during commit
docker commit -a="DeepInThought" -m="my redis" [redis container ID] myredis:v1.1
Data copy between container and host
copy the files in the rabbitmq container to the local path
docker cp rabbitmq:/[container_path] [local_path]
copy the host file to the rabbitmq container
docker cp [local_path] rabbitmq:/[container_path]/
Copy the host file to the rabbitmq container and rename the directory to [container_path] (note the difference from non renamed copy)
docker cp [local_path] rabbitmq:/[container_path]