CoderX
CoderX

Reputation: 1022

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

Upvotes: 8

Views: 8565

Answers (2)

wuta
wuta

Reputation: 21

To anyone who comes across this.

If you are running services in dev environment, and would like your containers to rebuild on code change automatically, you can use the docker compose watch command. To watch you will require additional setup in your docker-compose file. Check it out here.

Upvotes: 0

Mark S.
Mark S.

Reputation: 4019

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

Upvotes: 2

Related Questions