Hello, fellows!
I'm trying to use docker-compose
to run a composition with node server and a mongodb, which must use a docker volume to store its data. However, when I execute the docker-compose down
command, I lose all data that I've saved once before. When I docker volume list
, I'm able to list the volume created by docker-compose
.
I don't want to set a place in the host server to have the mongo data, if I use the ./data path as volume, data is persistent. However I want to easily manipulate it with docker volume
and such..
Here's a sample
version: '3.4'
services:
nodeserver:
build: .
container_name: "c-name"
ports:
- 3001:3001
- 80:80
links:
- mongodb
depends_on:
- mongodb
mongodb:
image: mvertes/alpine-mongo (if I use mongo I get the same behavior)
volumes:
- mongo-data:/var/data
container_name: "mongodb-service"
ports:
- 27017:27017
volumes:
mongo-data:
Versions:
docker-compose: 1.21.1
docker: 18.04.0-ce, build 3d479c0af6
system: Linux
Thanks in advance
Should work, try this docker-compose.yml
````
version: "2"
services:
test:
image: alpine:3.7
volumes:
- data:/app
volumes:
data:
````
````
docker-compose run --rm test sh -c "touch /app/toto && ls /app"
toto
docker-compose down
Removing network cliffhanger_default
docker-compose run --rm test sh -c "ls /app"
Creating network "cliffhanger_default" with the default driver
toto
````
Maybe this is an issue with mongodb, locking stuff?
docker-compose down
will not remove volumes unless specifically instructed to (with the -v
flag). Maybe you have an alias you forgot about? In the future please use the issue template and make sure to include the relevant output as well.
@ebuildy that actually worked. I'm starting to think this problem is about how mongodb deals with volume containers. Maybe I have to release some specific network configuration so it can use an external source to save its data. I've seen plenty of examples using mySQL with similar docker-compose.yml which worked quite well.
@shin-
docker-compose down will not remove volumes unless specifically instructed to (with the -v flag)
Actually, the volume itself is not removed. It appears that it's replaced every time I run docker-compose up
, that's why I lose my data. If I list the volumes after a docker-compose-down
, the mongo-data
is still available.
@herrmondlicht Did you ever solve this issue? We see a similar issue and I cannot imagine that nobody else hasn't too.
I'm also experiencing the same issue, any ideas on why?
FYI the issue is gone for us after switching to a named volume and mounting /data/db
instead of just /data
.
@mbrodala What about the configdb
folder?
BTW, mounting /data/db instead of /data worked for me thanks !
The configdb
is for the Mongo Config Server which we don't use currently. So we simply don't need it. ;-)
It seems @mbrodala solved it! Thanks man!
Not working on win10
Most helpful comment
FYI the issue is gone for us after switching to a named volume and mounting
/data/db
instead of just/data
.