Django/Docker: web container not up-to-date code

Hi,

I use Django docker app and do not manage to apply code update to my web container.

Docker version 20.10.14
docker-compose version 1.25.0

I’ve tried to delete all containers (docker rm -f ID ; docker system prune ) and images ( docker rmi -f ID ; docker image prune ) related to my app and re-build with docker-compose -f docker-comose.preprod.yml build

Then I run docker-compose -f docker-comose.preprod.yml up but for some reasons when I connect to my web running container ( docker exec -it web sh ) and read my updated files, I observe that update are not applied…

I have tried re-build using docker-compose -f docker-compose.preprod.yml build --force-rm --no-cache but I still observe the same issue: code in not up-to-date in web container

How should I do to make my update applied?

# Pull the official base image
FROM python:3.8.3-alpine

# Set a work directory
WORKDIR /usr/src/app

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies
RUN apk update && apk add postgresql-dev gcc g++ python3-dev musl-dev

RUN apk --update add libxml2-dev libxslt-dev libffi-dev musl-dev libgcc openssl-dev curl postgresql-client
RUN apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev nano
RUN pip3 install psycopg2 psycopg2-binary

# install xgettext for i18n
RUN apk add gettext

# Install dependencies
COPY requirements/ requirements/
RUN pip install --upgrade pip && pip install -r requirements/preprod.txt

# Copy the entrypoint.sh file
COPY entrypoint.preprod.sh .

# Copy the initdata sql file
COPY initdata.preprod.sql .

# Copy the project's files
COPY . .

RUN chmod +x entrypoint.preprod.sh
version: '3.7'

services:
    web:
        restart: always
        container_name: ecrf_web
        build:
            context: ./app
            dockerfile: Dockerfile.preprod
        command: gunicorn core.wsgi:application --bind 0.0.0.0:8000
        volumes:
            - app_volume:/usr/src/app
            - static_volume:/usr/src/app/static
            - media_volume:/usr/src/app/media
        expose:
            - 8000
        env_file:
            - ./.env.preprod
        entrypoint: [ "/usr/src/app/entrypoint.preprod.sh" ]
        depends_on:
            - redis
        healthcheck:
            test: [ "CMD", "curl", "-f", "http://localhost:8000/" ]
            interval: 30s
            timeout: 10s
            retries: 50

    redis:
        container_name: ecrf_redis
        image: "redis:alpine"

    celery:
        container_name: ecrf_celery
        build:
            context: ./app
            dockerfile: Dockerfile.preprod
        command: celery -A core worker -l info
        volumes:
            - app_volume:/usr/src/app
        env_file:
            - ./.env.preprod
        depends_on:
            - web
            - redis

    celery-beat:
        container_name: ecrf_celery-beat
        build:
            context: ./app
            dockerfile: Dockerfile.preprod
        command: celery -A core beat -l info
        volumes:
            - app_volume:/usr/src/app
        env_file:
            - ./.env.preprod
        depends_on:
            - web
            - redis

    nginx:
        container_name: ecrf_nginx
        build: ./nginx
        restart: always
        volumes:
            - static_volume:/usr/src/app/static
            - media_volume:/usr/src/app/media
        ports:
            - 1370:80
        depends_on:
            - web

volumes:
    static_volume:
    media_volume:
    app_volume:

This is where all you application related things are in your image:

This is what volumes you map againgst container folders (and therefore make the volume eclipse their whole content).

Now here commes the fun part: by default, if a named volume is empty, existing data from the image will be copied back into the volume. To make a named volume reflect the latest changes of the image, you would simply need to delete the volume and start with a new one. With bind mount volumes, existing data wouldn’t be copied - but the host folder content would still eclipse the container path content.

thanks for replying. I realize after posting here that I had volumes…