Docker usage commands and tricks

Introduction: Now that we have built Docker's basic commands and usage methods, we certainly have to learn, and some tips such as batch operation image acceleration and how to find suitable Docker-Images are the content of this section

Now that Docker's basic commands and usage methods have been built, of course we have to learn, and some tips such as batch operation image acceleration and how to find suitable Docker-Images are all covered in this section.
attach:
Meow's blog: w-blog.cn
Official Git address: https://github.com/moby/moby

1. 【Docker usage commands and tricks】Docker basic operation commands


Docker container lifecycle management
•docker run executes a command in a new container
•docker start starts one or more stopped containers
•docker stop stops a running container
•docker restart restarts a running container
•docker kill kills a running container
•docker rm removes one or more containers
•docker pause pauses all processes of a container
•docker unpaunse restores all processes of a container

【Docker usage commands and tricks 】Docker container operation and maintenance


•docker ps list containers
•docker inspect lists low-level information about a container or image
•docker top shows the processes running in a container
•docker attach attaches a running container
•docker events get real-time events from services
•docker log to get the log of a container
•docker wait blocks until a container stops, then prints its exit code
•docker export exports a container's filesystem as a tar file
•docker port lists the ports mapped by the container

【Docker usage commands and tricks 】docker version management


•docker commit creates a new image from a container
•docker cp copies a file or directory from a container to a local directory or stdout
•docker diff shows changes to a container's filesystem
docker image repository
•docker login to log in to the warehouse
•docker pull pulls the image
•docker push push image
•docker search search for images
Docker local image management
•docker images list local images
•docker rmi deletes the local image
•docker tag tag the local image
•a local image through Dockerfile
•docker history lists the history of the image
•docker save saves the local image as a tar file
•docker import imports images through tar
•docker load loads the tar image
docker other commands
•docker info
•docker version
2. Tips
Bulk operations
Many times it is found that it may be necessary to clean up the Docker environment, but it is too troublesome to stop the containers one by one and delete them one by one. Use the following commands to quickly process batch deletions
> docker ps // view all running containers
> docker stop containerId // containerId is the ID of the container
> docker ps -a // view all containers
> docker ps -a -q // View all container IDs
> docker stop $(docker ps -a -q) // stop stops all containers
> docker rm $(docker ps -a -q) // remove removes all containers
> docker rmi $(docker images -a -q) // delete all images
hub.docker
Since we use docker, we will use a lot of the environment mentioned by others. Often we go to https://hub.docker.com/ to find the mirror we need

Search for the mirror you need

By default, docker will pull from hub.docker when pulling an image. Use the following command to pull the first image above
docker pull richarvey /nginx- php -fpm
Domestic mirror warehouse and mirror source
For domestic mirror warehouses, you can apply for an Alibaba Cloud account and use its free Docker warehouse directly
The corresponding Docker source address needs to go to Alibaba Cloud Container Image Management to apply for and use other domestic Docker sources (if it is not configured, the subsequent K8S installation is very slow)
sudo mkdir -p / etc /docker
sudo tee /etc/docker/daemon.json << - ' EOF'
{
" registry -mirrors" : [ "https://xxxxxx.mirror.aliyuncs.com" ]
}
EOF

# restart
sudo systemctl daemon-reload
sudo systemctl restart docker
Note: The author has limited ability and I hope that everyone can point out the wrong places, and I hope to communicate more!

Copyright statement: The content of this article is contributed by Alibaba Cloud's real-name registered users. The copyright belongs to the original author. The Alibaba Cloud developer community does not own the copyright and does not assume the corresponding legal responsibility. For specific rules, please refer to the " Alibaba Cloud Developer Community User Service Agreement " and " Alibaba Cloud Developer Community Intellectual Property Protection Guidelines ". If you find any content suspected of plagiarism in this community, fill out the infringement complaint form to report it. Once verified, this community will delete the allegedly infringing content immediately.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00