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 . . EXPOSE 8080 CMD [ "npm", "start" ]
And I need to connect this application to a MongoDB container, which I do in my docker-compose file …
version: "3" services: app: container_name: database restart: always build: . ports: - "8080:8080" links: - mongo mongo: container_name: mongo image: mongo volumes: - /data:/data/db ports: - "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.