1. Docker container information
Docker info ## Docker info ## Docker --helpCopy the code
2. Mirror operation
Tip: You can use the image name, long ID, and short ID for mirroring operations.
2.1 Mirror View
## Docker images with intermediate image layer DOCker images-aCopy the code
'## show only the image ID docker images-q ## include intermediate image layer docker images-QA'Copy the code
## Docker images --no-trunc ## Docker images --no-trunc #Copy the code
Docker search MySQL ## --filter=stars=600: Docker search --filter=stars=600 mysql ## --no-trunc Mysql ## --automated: only lists the image of the docker search --automated mysqlCopy the code
2.2 mirror search
Docker search MySQL ## --filter=stars=600: Docker search --filter=stars=600 mysql ## --no-trunc Mysql ## --automated: lists only the image of the docker search --automated mysql 'Copy the code
2.3 Image download
## Download the latest official image of Redis, equivalent to: Docker pull redis:latest docker pull redis:latest Docker pull redis:latest Docker pull redis:latest Docker pull redis:latest Docker pull redis:latest Docker pull redisCopy the code
2.4. Mirror Deletion
Delete a single mirror, equivalent to: Docker rmi redis:latest docker rmi redis:latest docker rmi redis:latest docker rmi redis # Docker rmi -f tomcat nginx ## Docker images -f $(docker images -q)Copy the code
2.5. Mirror Building
# # (1) write dockerfile CD/docker/dockerfile vim mycentos # # (2) build a docker mirror docker build - f/docker dockerfile/mycentos - t Mycentos: 1.1Copy the code
3. Container operation
Tip: Use CONTAINER ID or NAMES for CONTAINER operations.
3.1 container startup
## Create a container and start it with -i to run the container in interactive mode. -t reassigns a dummy input terminal to the container. Docker run -d mycentos docker run -d mycentosCopy the code
Note: Docker ps-a will show that the container has already exited. This is how Docker works: in order for a Docker container to run in the background, there must be a foreground process.
Solution: Run the program you want to run as a console process.
## Start one or more stopped containers docker start redis ## Restart container docker restart redisCopy the code
3.2. Container processes
##top support ps command parameters, format: Docker top [OPTIONS] CONTAINER/ps OPTIONS listed # # redis CONTAINER running processes docker top redis # # for I see all the process of CONTAINER operation information in ` docker ps | grep Up|awk '{print $1}'`; do echo &&docker top $i; doneCopy the code
3.3. Container Logs
Docker logs rabbitmq docker logs rabbitmq -t Displays the timestamp. --tail lists only the latest N container logs; Docker logs -f-t --tail=20 redis ## Check the latest 10 logs of the container redis from May 21, 2019. docker logs --since="2019-05-21" --tail=10 redisCopy the code
3.4 Entry and exit of containers
Docker run -it centos /bin/bash Ctrl + P + Q # enter the terminal of the centos container startup command directly, no new process will be started. --sig-proxy=false Docker attach --sig-proxy=false centos # -i keeps STDIN open even if not attached; Docker exec -i -t centos /bin/bash # Docker exec -i -t centos ls -l/TMP ## Docker exec -d centos touch cache.txt 'is not returned to the current terminalCopy the code
3.5. View containers
Docker ps -a docker ps -a docker ps -a docker ps -sCopy the code
Docker ps -n 3 ## Do not truncate the output docker ps --no-truncCopy the code
Docker inspect --format='{{range 'docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redisCopy the code
3.6 Stop and delete containers
## Delete a docker rm -f from a running docker Redis # # to delete multiple containers docker rm -f $(docker ps - a - q) docker ps - a - q | xargs docker rm # # - l network connection between remove the container, Docker rm -l db ## -v delete container and delete volume docker rm -v redisCopy the code
3.7. Generate an image
Create a new image based on the current Redis container. Parameter: -a Submitted mirror author; -c use the Dockerfile command to create an image; -m: Description of submission; Docker commit -a="DeepInThought" -m="my redis" [redis ID] myredis:v1.1Copy the code
3.8 Data copy between containers and hosts
Docker cp rabbitMQ :/[container_path] [local_path] # copy host files to rabbitMQ docker cp [local_path] rabbitmq:/[container_path]/ ## Docker cp [local_path] rabbitmq:/[container_path]Copy the code