Docker-compose volume problem

I built an Express/Node application, created an image for it, and run a container which works fine on its own. Heres the Dockerfile for it…

FROM node:10

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm install --only=production

# Bundle app source
COPY . .

CMD [ "npm", "start" ]

And I need to connect this application to a MongoDB container, which I do in my docker-compose file …

version: "3"
    container_name: database
    restart: always
    build: .
      - "8080:8080"
      - mongo
   container_name: mongo
    image: mongo
      - /data:/data/db
      - "27017:27017"

My question is - do I have my volume syntax right? At first I was using ‘- ./data:/data/db’, with the dot in the beginning since the data folder needs to be in my app directory where the docker-compose file is. But every time I tried to run docker-compose up with the dot in the beginning of the volume path mongo would give an error and stop running. If I delete the volume from the docker-compose file altogether or if I remove the dot and run docker-compose up it seems to build fine without any errors.
I’m developing on a Windows machine so I’m concerned leaving the dot out of the volume path might work on Windows but probably wont work in an Ubuntu environment which is what I plan to use in production.
Thanks for any help you can give.

apparently MongoDB and mapped volumes in Docker on Windows are not compatible which is why
‘- ./data:/data/db’ does not work without errors, and ‘- /data:/data/db’ is the wrong syntax so it didnt work at all.

This really sucks. Does anyone know of a workaround? Or has anyone used something like a ‘mongo-express’ container for a development database?

/data is not a wrong syntax, just this folders doesn’t exists (Windows paths start with a drive letter).
Windows volumes are connected as a CIFS mount, where a many of the features of the file system are missing. This may be the reason why it still doesn’t work with the correct path.
The question is, do you really need access to the db files from Windows or do you just need persistent data? For the second create a named volume (

1 Like

thanks for the reply. You’re probably right, I probably dont really need the db mapped in a development environment. It would just be nice to see how MongoDB works behind the scenes a little more since I’m new to MongoDB and NoSQL databases.

Probably the best solution is to not map the db volume in development and map it in production for backups etc. Thanks again

Actually I don’t think this is correct. I’m using docker-compose (1.22.0 on Fedora 29) and get the same problem.

Docker-compose doesn’t seem to allow creating volumes with a dotfile in the mount name on either side of the stanza - works fine without one.

This works:

  - data:/dir/subdir

This doesn’t work using docker-compose. Volume is created just fine by docker when brought up without docker-compose:

  - data:/dir/.subdir

Anyone know of a way around this?

Are you trying to map the volume to a hidden folder? I haven’t tried that. I was trying to use the dot to tell docker to use the current directory, not map it from a hidden directory

Probably the same problem - it seems docker-compose doesn’t understand dots in file expressions.

docker-compose understands dots. you probably just cant write to a hidden folder

While reading this I just got a though, would it be possible to use git bash for windows: mkdir data as a workaraound?