Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Compose build command using Cache and not picking up changed files while copying to docker

I have a docker-compose.yml file comprising of two services (both based on a DockerFile). I have build the images once (using command: docker-compose build) and they were up and running once I ran this command (docker-compose up).
I had to change the source code used for one of the services, however, when I rebuilt the images (docker-compose build), the code changes were not reflected once I ran the services (docker-compose up).

docker-compose.yml

version: '2'

services:
  serviceOne:
    build:
      context: ./ServerOne
      args:
          PORT: 4000
    ports:
      - "4000:4000"
    env_file:
      - ./ServerOne/.env
    environment:
      - PORT=4000
  serviceTwo:
    build:
      context: ./serviceTwo
      args:
          PORT: 3000
    ports:
      - "3000:3000"
    env_file:
      - ./serviceTwo/.env
    environment:
      - PORT=3000
      - serviceOne_URL=http://serviceOne:4000/
    depends_on:
      - serviceOne  

serviceOne/DockerFile

FROM node:8.10.0

RUN mkdir -p /app
WORKDIR /app
ADD package.json package-lock.json /app/
RUN npm install
COPY . /app/
RUN npm build
EXPOSE ${ACC_PORT}
CMD [ "npm", "start" ]

serviceTwo/DockerFile

FROM node:8.10.0

RUN mkdir -p /app
WORKDIR /app
ADD package.json package-lock.json /app/
RUN npm install
COPY . /app/
RUN npm build
EXPOSE ${ACC_PORT}
CMD [ "npm", "start" ]

Following is the output of the docker-compose when it is ran for the second time.
It is some how using the cached images again when COPY and npm build command are ran.

How could the DockerFile or docker-compose file be changed so that the new source code is deployed?

enter image description here

like image 440
CoderX Avatar asked May 30 '26 13:05

CoderX


1 Answers

You can force the build to ignore the cache by adding on the --no-cache option to the docker-compose build

like image 182
Mark S. Avatar answered Jun 02 '26 02:06

Mark S.