Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New package.json packages are not showing in Docker container

I am using Docker with Docker Compose and these are my files:

#DOCKERFILE

FROM mhart/alpine-node 

# Create app directory
RUN mkdir -p /home/app

# Bundle app soure
COPY . /home/app

# From now on we work in /home/app
WORKDIR /home/app

# Install yarn and node modules
RUN echo -e 'http://dl-cdn.alpinelinux.org/alpine/edge/main\nhttp://dl-
cdn.alpinelinux.org/alpine/edge/community\nhttp://dl-
cdn.alpinelinux.org/alpine/edge/testing' > /etc/apk/repositories \
&& apk add --no-cache yarn \
&& yarn

EXPOSE 8080

This is the docker-compose file for dev:

app:
  build: .
  command: yarn start:dev
  environment:
    NODE_ENV: development
  ports:
    - '8080:8080'
  volumes:
    - .:/home/app
    - /home/app/node_modules

The problem I am having is that this setup seems to work just once because no matter which new module I add to the package.json, whenever I run docker-compose build it will not install the new package.

The reason why I am using the volumes is because nodemon would not work without .:/home/app, but if the node modules are not installed in the host then it will fail, reason why I need /home/app/node_modules. I suspect this could be the cause of my error, but I am not sure how to circumvent that.

like image 889
feychu Avatar asked Nov 01 '25 00:11

feychu


1 Answers

I solved this by moving my src code inside an src directory. This means my docker-compose.yml file now looks like this:

app:
  build: .
  command: yarn start:dev
  environment:
    NODE_ENV: development
  ports:
    - '8080:8080'
  volumes:
    - ./src:/home/app/src

Since I am not mounting the whole dir with the node_modules, new ones seem to be installed correctly.

like image 117
feychu Avatar answered Nov 03 '25 13:11

feychu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!