Docker always takes the older version

Hi, I have a project where I work with fastapi, mongodb and neo4j.
The problem I am facing is that when I update something for example adding or modifying a route, then I run docker compose build and docker compose up, it always takes the older version. So I am stuck.

Do any of you have a solution?

What do you mean by “it always takes the older version”?

The older version of the image, after having rebuilt it?

I think so. I would say the older version of my code

You probably use volumes and the volume is already populated so even if you build a new image, the data on the volume will not be replaced as the already existing volume is mounted over the new code

1 Like

I tried to delete all containers, images and volume on docker desktop, but still the same issue.

Share your compose file and commands you use.

Hi,
Here is my Dockerfile:

services:
  fastapi-app:
    build: .
    environment:
      - MONGO_CONNECTION_STRING=${MONGO_CLUSTER_URL}
      - PORT=80
    ports:
      - '${PORT}:${PORT}'
    volumes:
      - ./app:/code/app
    depends_on:
      - mongo
      - neo4j
    networks:
      - app-network

  mongo:
    image: mongo
    ports:
      - "27017:27017"
    volumes:
      - mongodb:/var/lib/mongodb/data
    networks:
      - app-network

  neo4j:
    image: neo4j:latest
    ports:
      - "7474:7474"
      - "7687:7687"
    environment:
      - NEO4J_AUTH=${NEO4J_AUTH}

    volumes:
      - ./db/data/:/data
      - ./db/config/:/config
      - ./db/logs/:/logs
      - ./db/plugins/:/plugins
    networks:
      - app-network

volumes:
  mongodb:
  neo4j_data:

networks:
  app-network:
    driver: bridge

And my Docker-compose.yml:

FROM python:3.9

# Définir le répertoire de travail

WORKDIR /code

# Copier les dépendances dans le conteneur

COPY ./requirements.txt /code/requirements.txt

# Installer les dépendances

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

# Copier le code de l'application dans le conteneur

COPY ./app /code/app

# Exposer le port 80 dans le conteneur

EXPOSE ${PORT}

# Utiliser Uvicorn pour lancer l'application FastAPI

CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT} --reload"]

I first build it with docker compose up and then docker compose build.

Here is a secret trick: use 3 backticks before and after code/config to make it more readable and preserve spacing, which is important for yaml.

```yml

yaml:
  code: here

```

I edited your post, but next time, please do as @bluepuma77 and @deanayalon described. More information about formatting is here: How to format your forum posts