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?
deanayalon
(Dean Ayalon)
October 18, 2024, 4:27pm
2
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
rimelek
(Ăkos TakĂĄcs)
October 18, 2024, 8:40pm
4
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.
bluepuma77
(Bluepuma77)
October 19, 2024, 7:31am
6
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.
bluepuma77
(Bluepuma77)
October 21, 2024, 6:46am
8
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.
rimelek
(Ăkos TakĂĄcs)
October 22, 2024, 10:08pm
10
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