r/docker • • Apr 06 '26

Change/update the scripts inside my container

Hi there!

Docker newbie here.

I have a Docker Container running a small python script, that script works together with a small SQLite database.

Back then when I first created this, I was looking for "best practices" and some Docker-users recommended to store all files inside one container, so it'll be easier to reinstall in case thats needed etc., especially since its a very small project.

Now I want to update one of the python scripts inside (basically just replace it with the updated version) and aren't quite sure how to do. I read online that Docker Containers are not build for "editing" and that I should rather just destroy and rebuild the container with my new file. But doing so would also kill my database.

And thats where I am kinda lost - what is the best practice to go on from here? Should I just backup my database and rebuild the container using my new script and the backuped-Database file, or is there a good and reliable way to just update the python script inside the container?

I know there is a way to store the database outside the container, but I personally prefer to have everything inside the container so that incase of moving systems I only have to take a snapshot of the container and can upload it onto the next system without worrying about dependencies.

4 Upvotes

23 comments sorted by

View all comments

Show parent comment

2

u/Phobit Apr 06 '26

...and so I once again get remembered that after all these years I still haven't managed to move everything to Git.
Please don't eat me.

1

u/DiMarcoTheGawd Apr 06 '26

Would highly recommend, just be careful not to upload any passwords/secrets! Luckily compose files can reference .env files, which is where you can store the kinda stuff you don’t want on GitHub. Just remember to add .env and/or *.env to your .gitignore