Adrian
Adrian

Reputation: 1549

Windows / Docker / External Mount

Before continuing, this setup completely works on my OSX.

Now, I need it also on a windows 10 machine. Again, everything works, except one thing.

When turning off everything with docker-compose down, MongoDb contents get erased.

As I've found out, a solution that might work is to create an external volume.

Which I did, with docker volume create mongodbdata. And it didn't work.

This is my docker-compose.yaml:

    version: '2'
    volumes:
        mongodbdata:
            external: true

    services:
        nginx:
            image: 'nginx:alpine'
            ports:
                - '8000:80'
            volumes:
                - './:/app'
                - './docker-nginx.conf:/etc/nginx/conf.d/default.conf'
        mongodb:
            image: mongo
            volumes:
                - 'mongodbdata:/data'
            ports:
                - '8001:27017'
            command: mongod --smallfiles --logpath=/dev/null

I tried to remove external:true in hope it will work with a local volume, and no luck there. I tried to put version '3' JUST in case, no luck.

The funny thing, while I was googling this, I somehow managed to do it. So I shut down everything with docker-compose down, and brought up everything, and somehow the data was there.

So it looks like, this might work, but I might be doing something wrong.

I tried all sort of combinations, and even managed to succeed a few times, but couldn't figure out how I succeeded or in other words couldn not find the pattern.

I would be grateful if somebody could share some knowledge.

If I missed any information, please let me know.

Thanks a lot!

BTW docker version is the latest, updated it just todat!

Upvotes: 1

Views: 2297

Answers (2)

Adrian
Adrian

Reputation: 1549

In the end, this had nothing to do with docker and volumes, the problem was in the docker-compose file.

mongodb:
    image: mongo
    volumes:
        - 'mongodbdata:/data'
    ports:
        - '8001:27017'
    command: mongod --smallfiles --logpath=/dev/null

More specifically, this section here:

    volumes:
        - 'mongodbdata:/data'

We switched this to

    volumes:
        - 'mongodbdata:/data/db'

and suddenly all works.

Not sure what's going on under the hood...

Upvotes: 2

Sergiu
Sergiu

Reputation: 3195

You will need something as follows:

   mongodb:
      image: mongo
      volumes_from:
         - mongodbdata
      ports:
         - '8001:27017'
      command: mongod --smallfiles --logpath=/dev/null
   mongodbdata:
     image: busybox
     volumes:
        - .:/data

Upvotes: 0

Related Questions