docker ps -a
docker stop container-java-eb
docker stop container-pgadmin-eb
docker stop container-postgresql-postgis-eb
docker rm container-java-eb
docker rm container-pgadmin-eb
docker rm container-postgresql-postgis-eb
docker rmi image-java-eb:v.1.0
docker rmi image-pgadmin-eb:v.1.0
docker rmi image-postgresql-postgis-eb:v.1.0
docker ps -a
docker volume ls
docker-compose up --build
I have noticed that every time I launch a new setup the volumes grow. When I delete a container I expect to delete all volumes as well, with the exception of the physical files on the OS. Why when I use the command ‘docker volume ls’ does the volume list grow continuously? How can I improve my approach and eliminate the volume with each new setup? I would like to delete the volume but not the files on the OS. Obviously I expect a more precise answer than the following: ‘docker volume rm $(docker volume ls -q)’.
Why when I run the following command after running the previous ones do I still get volumes?
docker volume ls
DRIVER VOLUME NAME
I have 3 volumes, I expect to always read only 3 volumes in the previous list. There is something I didn’t understand but I don’t know what. The above list consists of 5 lines. I have launched the installation commands 2 times so I deduce that every time I launch the installation commands a new record is created.
Another thing I’ve always asked myself: is it possible to give a name to a volume and then delete it? Basically a command similar to the one I use for images and containers.
All files in a volume is on the host filesystem. This is why I don’t understand this part of the question. When you use a smimple bind mount, then the files are not created by docker, so those will not be removed, but that is an other story, since you are talking about anonymous volumes. Just to clarify. When you create a volume, there is no “file inside the container and file on the host”. Those are the same files from two different poing of view. At least when you use Docker on linux without the Desktop, because the Desktop needs to complicate it more.
Maybe if you could show me an example and show me what exactly do you think a file on the host, I would understand.
I still don’t see any command to remove the volumes. Those volumes will not be removed automatically when you remove the container.
However, if your problem is that you don’t know where those volumes were defined, those could be defined in the Dockerfile of the image, or base image of your Dockerfile. You can use docker image inspect to check if an image has a volume . If it has, just define the same target path in your Docker compose file with a name, if you want to have a name.
Whether it has name or not, you can delete all volumes when you run docker-compose down --volumes
This is why I suggest to use that and don’t try to remove everything without docker-compose. Those commands are useful when somethinggoes wrong and you need to clear everything. Otherwise it is just creating more problem and requires more effort.
I thought the volume files were double, thanks. I understand your speech.
I thought that by removing the container the link to the volume would be deleted. Using ‘docker-compose down --volumes’ I no longer have a growing list using ‘docker volume ls’. Fantastic!
I also understood something else. When I run ‘docker-compose up --build’ from a 100% clean system I get this:
gi@Ubuntu-22:~/Dropbox/DOCKER/Server-Docker-Locale-01$ docker volume ls
DRIVER VOLUME NAME
I deduce that 2bb5abacffa9dbe33c48ea2cb79792cea075350d166ec822090ae20e3abc812f is the record relating to 2 volumes and precisely to the following:
server-docker-locale-01_data-postgresql should be relative to this volume:
Basically when I wasn’t using docker-compose down --volumes I would add double volume every time. At this point a spontaneous question arises: Is it possible to assign a name to a volume in the .yml file? Is it also possible to decide to remove a volume with a specific name, assigned by me, without using docker-compose down --volumes? How?
As for the networks I have a network called ‘eb’ (I have to change this name, I am aware of it). What would be the command to search for existing networks and delete only one with a name assigned by me?
Absolutely not.That is an anonymous volume. You will not find bind mounts among volumes.
You just did that. If you mean rename an anonymous volume, then no, it is not possible.
No. Even if the help inidicates that you could.
» docker-compose down --help
Usage: docker compose down
Stop and remove containers, networks
--remove-orphans Remove containers for services not defined in the Compose file.
--rmi string Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")
-t, --timeout int Specify a shutdown timeout in seconds (default 10)
-v, --volumes volumes Remove named volumes declared in the volumes section of the Compose file and anonymous volumes attached to containers.
It say --volumes volumes but it is really just --volumes without parameters.
You will have to open a new topic starting with how you tried to find a way, and why you could not solve it because I would not like to be an interactive documentation and this topic was not about networks initially. On the other hand I would just use docker-compose down to delete the networks and change the configuration, then run docker-compose up again.
I need to ask you again not to ask everything in one topic when you just have an other question because that will be end endless conversation. I know it is not easy when you have so many questions, but we need to keep the forum clean so people don’t need to ask the same thing again because they can’t find anything. In the future I also try not to answer unrelated questions which is hard for me. Also, please, always share how you tried to solve an issue like the one with deleting networks, so you can make sure that your post will not be ignored in favor of other posts where it is easier to answer when we have less time.