I encountered a strange issue with Docker last night, and I'm wondering if it's related to my Ubuntu setup. I updated some code and cleaned everything Docker-related, but when I ran my containers again, I got import errors for code I've already deleted. Here's what I did:
1. I ran `docker system prune -af` followed by `docker volume prune -af` just to be thorough.
2. I deleted a utility function from my Django code and removed all instances of its import in `tasks.py`.
3. When I executed `docker compose up --build`, I still got import errors related to that removed function. Has anyone else experienced this? What could be going wrong?
2 Answers
It sounds like you might not be rebuilding your Docker image correctly. When you're working with changes, make sure to use the `--no-cache` option when you build your containers to avoid using old layers that might still reference that deleted code. Also, ensure your volume mounts are set up correctly; if they’re not, you might be pulling in stale code from your local environment.
From what you've said, I think the problem might be that you’re starting the same containers with old images. Make sure when you build your images, you’re doing it fresh so any changes you made get picked up. If they aren't properly updating, that could cause the import errors you're seeing.
What info do you think is missing to help figure this out?
Definitely try `--no-cache`, that often clears up issues like this!