If you use docker for large-scale development but don't have a cleanup strategy, your disk will fill up quickly and when you really have to ship something immediately because the product is hot, you won't be able to ship it. When we run a process in a computer, once the process is completed, everything is destroyed. Containers are the infrastructure that many of us operate on today. Everything runs in a container, aiming to have one process per container. When the process is complete, the container exits. But it won't clean up on its own. What Docker has accumulatedYou need to pay attention to these
You may not care too much about disk space if you have enough space, but network is important too. By default, Docker uses the bridge network, which has a limit of 31 networks. When the limit is reached, you will see the following message: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network This can happen if you are a heavy docker-compose user who creates one network per project. You can fix the problem by setting a custom docker network create dada --subnet 192.167.11.0/24 But anyway, the point of this article is cleaning. Clean up with dockerCleaning up stopped containersdocker rm -v $(docker ps --all --quiet --filter 'status=exited') This will find all containers in the exited state and print their IDs one per line so we can feed it to other shell commands. We use Cleaning up disk volumesThe above command should remove the volume associated with this container. If you created volumes manually and want to delete any unused volumes: docker volume rm $(docker volume ls --quiet --filter 'dangling=true') Clean up the imageIt is usually safe to remove all Docker images. We can get it on demand when we need it. Usually after an image is cleaned, build times will be longer because the Docker daemon needs to spend time downloading the image again. docker rm --force $(docker images --quiet) Here, we use Cleaning up the networkIt's very simple. We can delete any network and it will be recreated later on demand. docker network rm $(docker network ls --quiet) Clean up with docker-composeIf you use docker-compose to start your containers, we have an easy way to clean up the resources associated with a specific compose file. docker-compose down --volumes --rmi all --remove-orphans Unfortunately, this command does not remove anonymous volumes, so you will have to deal with those. One command solves all problemsDocker is ephemeral, we can always re-obtain our image, re-create our database for development, or if this is just a continuous integration system, we can delete everything. docker system prune --all --force --volumes This concludes this article on common methods and issues of Docker cleanup. For more Docker cleanup content, please search 123WORDPRESS.COM’s previous articles or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Analyze the difference between querySelector and getElementById methods in JavaScript
>>: Eight rules for effective web forms
Preface: I encountered a requirement to extract s...
Written in front Nginx is not just a reverse prox...
The first one: normal operation SELECT SUM(ddd) A...
Table of contents Identifier length limit Length ...
Steps: 1. Install MySQL database 1. Download the ...
Table of contents 1. Modify the app.vue page 2. C...
Summary: Configure nginx reverse proxy jira and i...
1. Background In our daily website maintenance, w...
Table of contents I've been learning React re...
Table of contents Environment Setup Overview 1.Wh...
<br />According to statistics, the average s...
Trident core: IE, MaxThon, TT, The World, 360, So...
Easy installation of opencv2: conda install --cha...
1. I recently installed a new version of Ubuntu. ...
1. Phenomenon In the early morning, an index was ...