dockerdocker-composedockerfilecontainersdocker-build

Docker Compose up not detecting changes in code


I have a Dockerfile and Docker composefile as below.

My Dockerfile

FROM ubuntu:22.04 as build-deps

RUN apt-get update \
    && apt install -y nodejs \
    && apt install -y npm

COPY . /opt/mlops

WORKDIR /opt/mlops

RUN npm i && npm i chart.js 

#CMD ["npm", "start"]

RUN npm run build

FROM nginx:stable

COPY --from=build-deps /opt/mlops/build /usr/share/nginx/html

EXPOSE 80 

CMD ["nginx", "-g", "daemon off;"]

My Docker compose-file

version: '2'

services:
  frontend:
    build: .
    image: front:1.0
    ports:
      - "80:80"
    volumes:
      - frontend:/usr/share/nginx/html
    networks:
      - mlops
volumes:
  frontend:
networks:
  mlops:

The issue I am facing is even after deleting all images and building again, I am not able to detect changes on my website running in the container.

I am able to run the website.

It is a nodejs app.

I tried using docker compose build command, then used docker system prune --all to clear everything and then ran docker compose up -d but no luck still it is not updating


Solution

  • You have a docker volume here

    volumes:
      - frontend:/usr/share/nginx/html
    

    When a volume is first created, if there is any content in the image where the volume is mapped, that content is copied to the volume (See https://docs.docker.com/storage/volumes/#populate-a-volume-using-a-container). That happens the first time you run your container. And on all subsequent runs, there's already something in the volume, so the fresh content you have isn't copied to the volume. That's why you keep seeing the old content.

    I don't see the point of having the volume and I would remove those 2 lines in your docker-compose file. After that, you should see the content of the updated image (after you've stopped the container and started a new one).