docker commands you may not be aware of
- 2021-01-02 22:05:36
- OfStack
Intro
Introduces and includes 1 simple but rarely used docker commands that may be used
dangling images
In the case of build's own docker image, it is sometimes encountered with one or more mid-tier images, which will reduce the size of the final packaged docker image to a certain extent, but will result in 1 useless image of tag as none, also known as suspended image (dangling images).
List all dangling images:
docker images -f "dangling=true"
Delete all dangling images:
docker rmi $(docker images -f "dangling=true" -q)
The batch operation
When the server restarts or shuts down for some reason, the docker containers may need to be restarted entirely, starting all docker containers
Note: If there are dependencies, such as link, these dependent containers should be started first
docker start $(docker ps -aq)
Stop all docker containers
docker stop $(docker ps -aq)
Delete all docker containers
docker rm $(docker ps -aq)
Delete all docker images
docker rmi $(docker images -q)
docker resource cleanup
docker container prune # Delete all containers in exit status
docker volume prune # Deletes unused data volumes
docker image prune # delete dangling Or all unused mirrors
docker system prune # Delete the stopped container, dangling Mirror, not referenced by the container network And during the build process cache
# To be safe, this command does not delete volumes that are not referenced by any container by default. If you want to delete these volumes at the same time, you need to specify explicitly --volumns parameter
docker system prune --all --force --volumns # Not only will the data volume be deleted this time, but there will be no validation! Notice, use --all Parameter will delete all unreferenced images instead of just dangling The mirror
Reference
https://www.ofstack.com/article/143173.htm
conclusion