Hey everyone! I'm new to Docker and have a container running a small Python script that interacts with an SQLite database. When I set it all up, I followed advice that suggested keeping everything in one container for ease of reinstallation, especially since it's a small project. Now, I want to update one of the Python scripts inside the container, but I'm unsure about the best way to go about it. I've read that Docker containers aren't really made for editing once they're running, and that I should rebuild the container with the new script. Here's the catch: that would wipe my database as well. Should I just back up my database and rebuild the container using the new script along with the backed-up database? Or is there a reliable way to just update the script inside without losing my data? I'm aware there are ways to store a database outside the container, but I prefer keeping everything inside for portability. Any advice would be much appreciated!
1 Answer
It's a common pitfall to keep everything inside the container. The best way to handle your situation is indeed to back up your SQLite database, then update your container with the new script. After that, recreate the container but use volume mounts to keep your database safe on your host system. This way, your container can be rebuilt without losing your database. Check the Docker documentation for how to implement mounts correctly!

So just to clarify, if I switch systems, I have to remember to set up those mounts again on the new host, right? I was hoping for a single command solution to handle everything. It’s doable, but I just want to weigh all my options.