HiveBrain v1.2.0
Get Started
← Back to all entries
patterndockerMinor

Understanding how Docker volumes work with compose

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
understandingvolumesdockerwithworkcomposehow

Problem

In the Docker Compose example for WordPress, the Ycode listing [1] says:

volumes:
   - db_data:/var/lib/mysql


What is exact meaning here? To compare, while using the Docker client, you can map volume to a host folder [2]:

-v /src/webapp:/webapp



This command mounts the host directory, /src/webapp, into the container at /webapp.

[1] https://docs.docker.com/compose/wordpress/#define-the-project

[2] https://docs.docker.com/engine/tutorials/dockervolumes/#locate-a-volume

Solution

db_data:/var/lib/mysql simply means that the db_data volume that was previously created will be made available in the container at /var/lib/mysql.

In you example it's created at the very end of the compose file.

From the Docker documentation: "The docker volume db_data persists any updates made by Wordpress to the database."

Compose volumes works the same way as the Docker engine.

In you case db_data is just a named volume instead of a path like your second example.

Context

StackExchange DevOps Q#1372, answer score: 6

Revisions (0)

No revisions yet.