Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: where is docker volume located for this compose file

I was setting up some materials for a trainning, when I came around this sample compose file:

https://github.com/dockersamples/example-voting-app/blob/master/docker-compose.yml

and I couldn't find out how this volume is mounted, on lines 48 and 49 of the file:

volumes:   db-data: 

Can someone explain me where is this volume on the host? Couldn't find it and I wouldn't like to keep any postgresql data dangling around after the containers are gone. Similar thing happens to the networks:

networks:   front-tier:   back-tier: 

Why docker compose accepts empty network definitions like this?

like image 547
Vini.g.fer Avatar asked Jul 24 '17 01:07

Vini.g.fer


People also ask

Where are Docker compose files located?

The default path for a Compose file is ./docker-compose.yml .

What does volume mean in Docker compose file?

Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. While bind mounts are dependent on the directory structure and OS of the host machine, volumes are completely managed by Docker.

Does Docker compose create volume?

We can also create a volume with Docker compose service or also specify existing volumes. For example, the following screenshot shows a 'docker-compose' file that creates a docker-compose service with a volume. As a result of the above command, a volume with the name 'myvolume' gets created.

How do I check if a docker volume exists?

Check if a Docker container exists We start by outputting a list of containers with any status, we search for a testContainer text in the output and we count the resulting lines. If the number of lines is greater than zero, we output testContainer exists . otherwise, we output testContainer does not exist .


1 Answers

Finding the volumes

Volumes like this are internal to Docker and stored in the Docker store (which is usually all under /var/lib/docker). You can get a list of volumes:

$ docker volume ls DRIVER              VOLUME NAME local               1c59d5b7e90e9173ca30a7fcb6b9183c3f5a37bd2505ca78ad77cf4062bd0465 local               2f13b0cec834a0250845b9dcb2bce548f7c7f35ed9cdaa7d5990bf896e952d02 local               a3d54ec4582c3c7ad5a6172e1d4eed38cfb3e7d97df6d524a3edd544dc455917 local               e6c389d80768356cdefd6c04f6b384057e9fe2835d6e1d3792691b887d767724 

You can find out exactly where the volume is stored on your system if you want to:

$ docker inspect 1c59d5b7e90e9173ca30a7fcb6b9183c3f5a37bd2505ca78ad77cf4062bd0465 [     {         "Driver": "local",         "Labels": null,         "Mountpoint": "/var/lib/docker/volumes/1c59d5b7e90e9173ca30a7fcb6b9183c3f5a37bd2505ca78ad77cf4062bd0465/_data",         "Name": "1c59d5b7e90e9173ca30a7fcb6b9183c3f5a37bd2505ca78ad77cf4062bd0465",         "Options": {},         "Scope": "local"     } ] 

Cleaning up unused volumes

As far as just ensuring that things are not left dangling, you can use the prune commands, in this case docker volume prune. That will give you this output, and you choose whether to continue pruning or not.

$ docker volume prune WARNING! This will remove all volumes not used by at least one container. Are you sure you want to continue? [y/N] 

"Empty" definitions in docker-compose.yml

There is a tendency to accept these "empty" definitions for things like volumes and networks when you don't need to do anything other than define that a volume or network should exist. That is, if you want to create it, but are okay with the default settings, then there is no particular reason to specify the parameters.

like image 95
Dan Lowe Avatar answered Sep 24 '22 11:09

Dan Lowe