5

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

Ta Mu
  • 6,772
  • 5
  • 39
  • 82

1 Answers1

6

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.

Wassim Dhif
  • 214
  • 1
  • 4
  • so in this case there is no host mapping, and Docker knows that db_data is so to say a link between Wordpress container and the /var/lib/mysql folder in the db container? – Ta Mu Jun 20 '17 at 13:18
  • 1
    Host mapping and volumes are two different things. db_data is not an host nor a container, it's a named volume.

    Remember that the named volumed is declared at the end of the copose file.
    You are just linking a volume inside a container, that's all.

    – Wassim Dhif Jun 20 '17 at 13:53
  • I think, I used an ambigous wording for "host mapping" - I meant "mapping to a host folder" – Ta Mu Jun 21 '17 at 06:30
  • I see, actually you have the volumes, that does the "mapping to a host folder" part and you have links, that does the "DNS mapping" part. – Wassim Dhif Jun 21 '17 at 07:55