Docker Community Forums

Share and learn in the Docker community.

Files written by container not visible on host

On my dev machine I’m running MongoDB inside a docker container (Docker Native 1.13.0-rc2-beta31, MacOSX).
Here’s the docker-compose.yml:

version: '2'
    image: mongo
    - 27017:27017
    - ./mongo-data:/data

It starts smoothly and creates 2 directories inside of ./mongo-data: db and configdb.
Now the strange thing:

  • if I ls ./mongo-data/db or ls ./mongo-data/configdb from the host I don’t get any file listed
  • if I do the same (ls /data/db or ls /data/configdb) from inside the container I see the MongoDB files I’m expecting to see there

What’s goin on here?

One more thing: if I erase the directories from the host they and their content get erased from the container as well.

Any help on this?


On thing that’s even more strange is that when I delete the files from the host the mongo process goes nuts, but if I restart via docker-compose up --force-recreate the files I deleted seem to be there again untouched (in the container).

Still unable to understand what’s going on here but I found something that seems to be working for my dev purposes: specify the data directory with the --dbpath flag.
In my specific case the docker-compose.yml gets a new line:

command: ["--dbpath=/data"]

Hope it helps someone. Also hope somebody can explain me why it is!