0

What I am doing wrong?

I have a dockerfile like this

FROM node:alpine
RUN mkdir -p /usr/src/node-app && chown -R node:node /usr/src/node-app
WORKDIR /usr/src/node-app
COPY package.json yarn.lock ./
USER node
RUN yarn install --pure-lockfile
COPY --chown=node:node . .
EXPOSE 3000

When I build the image manually dependencies are installed, I can run a container with it and node_modules folder is present. When I use docker-compose dependencies are not installed and I have to install them with a script after.

My docker-compose.yml

version: '3'
services:
node-app:
build: .
image: node-app
environment:
      - MONGODB_URL=mongodb://mongodb:27017/node-boilerplate
ports:
      - '3000:3000'
depends_on:
      - mongodb
volumes:
      - .:/usr/src/node-app
networks:
      - node-network
mongodb:
image: mongo:4.2.1-bionic
ports:
      - '27017:27017'
volumes:
      - dbdata:/data/db
networks:
      - node-network
volumes:
dbdata:
networks:
node-network:
driver: bridge

What am I doing wrong? Any tips about docker are appreciated, I am a total noob.

Banned
  • 9
  • 3
  • Please [edit] the post and format the `docker-compose.yml` properly. – Turing85 Dec 24 '21 at 20:16
  • This is the classic mistake to make with volumes: https://stackoverflow.com/questions/30043872/docker-compose-node-modules-not-present-in-a-volume-after-npm-install-succeeds. That'll tell you what you need to know. – Robert Moskal Dec 24 '21 at 20:23

0 Answers0