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

<p>In you example it's created at the very end of the compose file.<br>
From the Docker documentation: "The docker volume db_data persists any updates made by Wordpress to the database."</p>

<p>Compose volumes works the same way as the Docker engine.</p>

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

CC BY-SA 3.0
2017-06-20T13:18:34.860Z
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
CC BY-SA 3.0
2017-06-20T13:53:16.510Z
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
CC BY-SA 3.0
2017-06-21T06:30:19.443Z
I think, I used an ambigous wording for "host mapping" - I meant "mapping to a host folder"
Ta Mu
CC BY-SA 3.0
2017-06-21T07:55:13.630Z
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
CC BY-SA 3.0
2017-06-20T11:28:25.987Z
2017-06-20T11:28:25.987Z
Wassim Dhif
<p>In the Docker Compose example for WordPress, the Ycode listing [1] says:</p>

<pre><code>volumes:
   - db_data:/var/lib/mysql
</code></pre>

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

<pre><code>-v /src/webapp:/webapp
</code></pre>

<blockquote>
  <p>This command mounts the host directory, <code>/src/webapp</code>, into the container at <code>/webapp</code>. </p>
</blockquote>

<p>[1] <a href="https://docs.docker.com/compose/wordpress/#define-the-project" rel="noreferrer">https://docs.docker.com/compose/wordpress/#define-the-project</a></p>

<p>[2] <a href="https://docs.docker.com/engine/tutorials/dockervolumes/#locate-a-volume" rel="noreferrer">https://docs.docker.com/engine/tutorials/dockervolumes/#locate-a-volume</a></p>

<docker><docker-compose>
Understanding how Docker volumes work with compose
Ta Mu
# Understanding how Docker volumes work with compose

(Asked by: username_0 on 2017-06-19)

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

**Tags:** docker, docker-compose


---

## 1 answers

### Answer by username_1 on 2017-06-20. Score: 6 | Accepted answer

`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.

> **Comments:**
> **username_0**: 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?  
> **username_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.  
> **username_0**: I think, I used an ambigous wording for "host mapping" - I meant "mapping to a host folder"  
> **username_1**: 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.  

---

