Hello! I’m currently using Docker on two devices with one on Arch and one on MacOS. The Mac version seems to be alright with any code changes automatically triggering Watchfiles to restart and apply the changes. However with Linux, it seems to be inconsistent where it could be working for a bit and sometimes, it won’t. I have to rebuild the entire container to apply these changes.
I have already mounted the entire application to the app directory in the container.
services:
backend:
build:
context: . # This points to the parent directory of the /dev folder
dockerfile: Dockerfile
container_name: backend
volumes:
- .:/app
I could not give the entire Dockerfile since I am not sure how sensitive the information is. But based on my other Docker-based projects also, mounting the volume works on having the container refresh on code changes. Both containers are also hosted locally with the drives also being local. Any ideas why this could be happening? Thanks!
Hello! Used to use Docker Desktop on both but found out it was the same case. Tried using Docker engine only and it was still the same issue. What’s weird is that other docker containers that I have on the Linux machine (not running at the same time although smaller) seem to trigger the restart by watchfiles consistently except for this container which is bigger in terms of project size.
I have already tried:
Using watch instead of volume binding on sync+restart
Inotify limits are already on 524288.
Recloning and rebuilding the container multiple times.
EDIT: For more context, all projects (the smaller and bigger one) are FastAPI projects and already have the reload flag on uvicorn.
Since inotify would have been my next idea, I think I have none. I don’t work with projects currently that need to reload automatically so I don’t experience such issues.
Does it work when running outside containers, directly on the host?
I seem to have fixed the error by setting user: "0:0" on the docker compose file. I know this basically grants the container root user permissions. Would this cause any issues?
I say it often, but it depends on the application. It is not good in terms of security, but you know that.
You could try Docker CE as rootless Docker (running as your user). Then you can edit it, but your user would be root in the container and the root in the container would not be root on the host.
Thank you so much! I learned a lot today. I’ll definitely look into the cons of setting this in compose but for now, I’m just happy I’m able to edit my files and have it reflect immediately. Have a great day!