title: Docker-Compose: how to mapping volume from host into container?
body: <h2>The Problem:</h2>
  
  <p>I'd like to share a folder from the docker host with a specific container using docker-compose. A container running MongoDB shall place its data files into /var/lib/mongodb, but this folder shall be a mount to the hosts folder /var/lib/mongodb.</p>
  
  <p>But it still remains an own local directory within the container, not the shared one from the host.</p>
  
  <p>Sometimes it also ends up with the following warning:</p>
  
  <blockquote>
    <p>WARNING: Service "mongodb" is using volume "/var/lib/mongodb" from the
    previous container. Host mapping "name_dbvolume" has no effect.
    Remove the existing containers (with <code>docker-compose rm mongodb</code>) to
    use the host volume mapping.</p>
  </blockquote>
  
  <h2>docker-compose.yml</h2>
  
  <pre><code>version: '2'
  services:
    loopback:
      build: .
      expose:
        - "80"
        - "443"
        - "28015"
        - "29015"
      ports:
        - 3000:3000
      links:
        - mongodb
      environment:
        VIRTUAL_HOST: api.xxxxxx.com
        VIRTUAL_PORT: 3000
        LETSENCRYPT_EMAIL: yyyyyy@xxxxxxx.com
        LETSENCRYPT_HOST: api.xxxxx.com
    mongodb:
      build: ./MongoDB
      ports:
        - "27017:27017"
        - "27018:27018"
        - "27019:27019"
        - "28017:28017"
      volumes:
          - dbvolume:/var/lib/mongodb
  volumes:
      dbvolume:
  </code></pre>
  
  <h2>Dockerfile for MongoDB-Container:</h2>
  
  <pre><code>FROM mongo:latest
  
  RUN  mkdir -p /var/lib/mongodb &amp;&amp; \
       touch /var/lib/mongodb/.keep &amp;&amp; \
       chown -R mongodb:mongodb /var/lib/mongodb
  
  
  ADD mongodb.conf /etc/mongodb.conf
  
  VOLUME [ "/var/lib/mongodb" ]
  
  # EXPOSE 27017
  
  USER mongodb
  WORKDIR /var/lib/mongodb
  
  ENTRYPOINT ["/usr/bin/mongod", "--config", "/etc/mongodb.conf"]
  CMD ["--quiet"]
  </code></pre>
  
  <p>The mongodb-container is configured that MongoDB uses /var/lib/mongodb as data directory. With the following command we try to use this folder from the host:</p>
  
  <p>VOLUME [ "/var/lib/mongodb" ]</p>
  
  <p>What did i wrong here?</p>