Docker Community Forums

Share and learn in the Docker community.

Does using --restart always save everything?


(Linux4sec) #1

I was having trouble starting a docker automatically when I started the server, so I used “–restart always”.

It solved my problem because it starts the container automatically, but I noticed that unlike before, when I used CTRL + D or exit, that it did not save anything I did … right now leaving the wrong way it saves everything!

My question is: should --restart always, really should save everything? was not it just to restart the docker when it was closed?

And what are the possible problems I will have using this command?

Thank you!

(Sam) #2

restart doesn’t ‘save’… when a container stops, the files are as they were at the time.
if you start (or have a restart policy for always), then those files will be in the state on the last stop.

if you want to SAVE the exact state, then you would use docker commit container_id new_label_name
to create a NEW image to create new instances from at the new file state, the original image is untouched, and the source container are untouched…

good discussion here

(Think) #3

if you do not want the “save”-behavior, you can modify your CMD or ENTRYPOINT and clean there any state left from previous sessions.

(Sam) #4

yes, YOU have to account for that requirement (not keep modified files) and do whatever cleanup needs to be done,

(Think) #5

just if you use containers in a way they are not intented to be used.
containers should be immutable. state should be stored somewhere outside.
could you modify your container, that you could start it with --read-only?