2

I'm trying to run the a docker-compose operation which spawns up a Redis and MongoDb instance and which (should) provide the MongoDb instance with a data-file from the host pc through the volumes specification.

I can successfully boot up the container using the following docker-compose.yml:

redis:
  image: redis
  ports:
   - "6379:6379"
mongo:  
  image: mongo:latest
  volumes:
    - ./data/db:/data/db
  ports:
    - "27017:27017"
  command: --rest

assuming it should 'mount' the directory data/db of which the data dir is next to the docker-compose.exe file.

enter image description here

I can connect to both Redis and MongoDb, but a simple query on a collection performing a count() returns 0 (which should contain data). Which leads me to believe that the mounting of the volumes property isn't working.

If I check the file structure on the container I don't see a /data folder... Am I missing something here... Thanks for any lead!

enter image description here

Ropstah
  • 17,538
  • 24
  • 120
  • 194

1 Answers1

2

What you are showing is the filesystem of boot2docker, the TinyCore-based Linux host which runs the docker daemon.
It is not:

And that will only works if your files are in C:\users\... or /Users/..., which is the only host folder mounted by VirtualBox in the Linux VM.

To check if the mount has taken place, do a docker exec mongo bash, to open a bash in that container and check ls /data.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • ok cool, I was able to see through `Kitematic` that a volume was being mounted, however it was not pointing to the local directory that I specified. The fact that it needs to be in a `c:\users` directory solved it. I moved everything there and now it mounts the correct volume. Too bad that the data can't be loaded which means the container can't be started... (Text file busy: "/data/db/journal/j._0") – Ropstah Jan 24 '16 at 20:17
  • @Ropstah Note that you can mount other folders in boot2docker (http://stackoverflow.com/a/33998695/6309: see also the other answer on that same page) – VonC Jan 24 '16 at 20:19
  • Thanks for clearing up. I think I see the error and it is related to permissions on the `/data/db` folder. Somehow the container is unable to write to those files... I'm gonna mark your answer as answer, but hopefully you can point me out where those permissions should be set... – Ropstah Jan 24 '16 at 20:28
  • 1
    @Ropstah As an example: https://github.com/docker/docker/issues/7198#issuecomment-171964087, or http://stackoverflow.com/a/24986166/6309, or https://github.com/denderello/symfony-docker-example/issues/2#issuecomment-94387272 – VonC Jan 24 '16 at 20:31
  • Thanks for your link suggestions. However I'm not really sure as to what I need to do to fix it. I cannot start up my container due to the permissions. Only thing I can imagine is doing some `chown` operation on the host (which is Docker right? Not my local pc running the docker VM?) where the `/data/db` folder resides for the `mongodb:mongodb` user/group or something? – Ropstah Jan 24 '16 at 20:46
  • Those links are about setting the right permission through the Dockerfile, before runtime. – VonC Jan 24 '16 at 20:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/101533/discussion-between-ropstah-and-vonc). – Ropstah Jan 24 '16 at 20:50