title: How to share data between host and containers using volumes in Docker Compose
body: <p>I am playing with Docker Compose and volumes </p>
  
  <pre><code>version: '2'
  services:
      php-apache:
          env_file:
            - dev_variables.env
          image: reypm/php55-dev
          build:
              context: .
              args:
                  - PUID=1000
                  - PGID=1000
          expose:
              - "80"
              - "9001"
          extra_hosts:
              # IMPORTANT: Replace with your Docker Host IP (will be appended to /etc/hosts)
              - "dockerhost:xxx.xxx.xxx.xxx"
          volumes_from:
              - volumes_source
      volumes_source:
          image: tianon/true
          volumes:
              - ../:/var/www
      volumes_data:
          image: tianon/true
          volumes:
              - ./data/sessions:/sessions
  </code></pre>
  
  <p>Let's take the following facts:</p>
  
  <ul>
  <li>I have a directory under the host at: <code>~/var/www</code></li>
  <li>The data in such directory should persist regarding container status.</li>
  <li>The container should write the data from the host under <code>/var/www</code></li>
  </ul>
  
  <p>I have read docs <a href="https://docs.docker.com/engine/tutorials/dockervolumes/" rel="noreferrer">here</a> but is not clear to me how to deal with data volumes and host data.</p>
  
  <p>I want to share the data on the host with the container but I don't even know if the <code>docker-compose.yml</code> file above is right or what needs to be changed in order to achieve what I need. I know how to do it using <code>docker run</code> alone but doesn't have a clue for Docker Compose?</p>
  
  <p>Can any help me to get this working?</p>
  
  <p><strong>Update: playing with this</strong></p>
  
  <p>I have added this lines to the <code>docker-compose.yml</code> file:</p>
  
  <pre><code>    volumes_from:
          - volumes_source
  </code></pre>
  
  <p>And I run the <code>docker-compose up</code> once again but this is the result:</p>
  
  <pre><code>php55devwork_volumes_data_1 exited with code 0
  php55devwork_volumes_source_1 exited with code 0
  </code></pre>
  
  <p>I am not sure what is happening or why I am getting the error, any?</p>