The Problem:
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.
But it still remains an own local directory within the container, not the shared one from the host.
Sometimes it also ends up with the following warning:
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
docker-compose rm mongodb) to use the host volume mapping.
docker-compose.yml
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: [email protected]
LETSENCRYPT_HOST: api.xxxxx.com
mongodb:
build: ./MongoDB
ports:
- "27017:27017"
- "27018:27018"
- "27019:27019"
- "28017:28017"
volumes:
- dbvolume:/var/lib/mongodb
volumes:
dbvolume:
Dockerfile for MongoDB-Container:
FROM mongo:latest
RUN mkdir -p /var/lib/mongodb && \
touch /var/lib/mongodb/.keep && \
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"]
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:
VOLUME [ "/var/lib/mongodb" ]
What did i wrong here?