1. Docker container information
## View docker container info ## View docker container help docker --help
2. Mirror operation
Tip: For mirroring operations, you can use the mirror name, the mirror long ID, and the mirror short ID. Of the 20 Docker commands, how many do you know?
2.1, mirror view
## Contains the intermediate image layer docker images-a
## docker images-q ## contains intermediate image layer docker images-qa
## show full ests from docker images --no-trunc
## Shows the creation history of the specified image; Parameters: -h mirror size and date, default to true; --no-trunc displays complete submission records; -q only lists submitted record ID docker history-h redis
2.2. Mirror search
## --filter=stars= 100: Mysql ## docker search "starts>=600" --filter=stars=600 mysql ## -- docker search "starts>=600" --filter=stars=600 mysql ## -- docker search Mysql ## --automated: list only Docker Search with automated =OK --automated MySQL
2.3. Mirror download
## Download the latest Redis official image. Docker Pull Redis ## Download Docker Pull Bitnami/Redis ## Download Docker Pull Bitnami/Redis ## Download Docker Pull Bitnami/Redis ##
2.4. Mirror deletion
## delete a single image Docker RMI Redis: Latest Docker RMI Redis ## ForceDelete Docker RMI Redis ## ForceDelete Docker RMI Redis ## ForceDelete Docker RMI Redis ## ForceDelete Docker RMI Redis ## Docker rmi-f $(docker images-q) docker rmi-f $(docker images-q) docker rmi-f $
2.5. Mirror build
# # (1) write dockerfile CD/docker/dockerfile vim mycentos # # (2) build a docker mirror docker build - f/docker dockerfile/mycentos - t Mycentos: 1.1
Can you tell me the difference between a container and a mirror?
3. Container operations
Tip: You can use Container ID or Names for CONTAINER operations.
Recommended reading: Ultra detailed 280 pages of Docker combat documentation! Open the download
3.1. Container startup
## Create a new container and start it. -i Run the container in interactive mode. -t reassigns a pseudo-input terminal to the container; Docker run -i -t --name myCentOS ## -d docker run -d myCentOS # -d docker run -d myCentOS # -d docker run -d myCentOS
Note: Use “Docker PS-A” to find that the container has already quit. This is Docker’s mechanism: In order for the Docker container to run in the background, there must be a foreground process. Solution: Run the program you want to run as a previous process.
Docker Restart Redis is a container that has already been stopped
The Ultimate Docker Getting Started Guide! Learn and use
3.2 Container processes
##top supports 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; done
3.3. Container log
# # to check the redis container log, the default parameters docker logs the rabbitmq # # to check the redis container log, parameters: -f trace log output; -t displays the timestamp; --tail lists only the last N container logs; Docker logs -f-t --tail=20 redis ## View the latest 10 redis logs from the container redis after May 21, 2019. docker logs --since="2019-05-21" --tail=10 redis
Log management recommended reading: Docker Log Management Best Practices
3.4 Container entry and exit
Docker run-it centos /bin/bash/docker run-it centos /bin/bash/docker run-it centos /bin/bash Ctrl + P + Q ## Go directly to the terminal of the CentOS container startup command without starting a new process. Multiple ATTACH connections share the container screen. --sig-proxy=false -- make sure that Ctrl-D or Ctrl-C don't close docker attach --sig-proxy=false centos ## Open a new interactive terminal in the centos container and start a new process with: -i keeps STDIN turned on even if no attachment is attached; -t allocates a pseudo-terminal docker exec-i-t centos /bin/bash ## to execute commands in the container in interactive mode. Docker exec-d centos touch cache.txt; / / docker exec-d centos touch cache.txt; / / docker exec-d centos touch cache.txt; / / docker exec-d centos touch cache.txt; / / docker exec-d centos touch cache.txt; / / docker exec-d centos touch cache.txt; / / docker exec-d centos touch cache.txt
3.5. Look at the container
## View the ID of the running container docker ps-q ## View the running + history of the running container docker ps-a ## Show the total file size of the running container docker ps-s
Docker ps --no trunc docker ps --no trunc docker ps --no trunc docker ps --no trunc docker ps --no trunc docker ps --no trunc
Docker inspect redis ## retrieve IP docker inspect for running container redis --format='{{range ' .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redis
3.6 Stop and delete the container
## Delete a docker rm redis ## Delete a docker rm -f 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, Connect with the name DB Docker RM-L DB ## -V to delete the container and delete the data volume Docker RM-V Redis mounted on the container
3.7. Make mirroring
## Create a new image based on the current Redis container; Parameter: -a submitted mirror author; -c uses the Dockerfile directive to create the image; -M: Instructions at the time of submission; Docker commit -a="DeepInThought" -m="my redis" [redis container ID] myredis:v1.1
3.8. Copying data between container and host
RabbitMQ :/[container_path] [local_path] rabbitMQ :/[container_path] [local_path] rabbitMQ :/[container_path] [local_path [local_path] rabbitMQ :/[container_path]/ # Copy the host files to the rabbitMQ container. Directory rename to [container_path] docker cp [local_path] rabbitMQ :/[container_path]
Recommend reading for those who need to learn more about the Docker technology stack: The most complete and detailed Docker learning materials in history
Author: DeepInThought reference: https://www.cnblogs.com/DeepI…