How to "restart=always" with a fresh container?

911 views
Skip to first unread message

Art

unread,
May 11, 2016, 1:29:33 PM5/11/16
to docker-dev

I understand that "restart=always" will keep the same container (and underlying file system) each time it is restarted. However, I have a situation where what I need is the "restarting" behavior, but with a fresh container and a new instance of the file system.

Is there a way to run a docker container so that it restarts in its pristine, initial condition each time it exits?

Since someone will ask, the particular application is a container that runs a server to do work, and when the work is done the server shuts down. Since it is the entrypoint, it takes the container with it. Rather than restart *that* particular container, I'd like a new container to spring up with everything reset to the starting point.

Seán C. McCord

unread,
May 12, 2016, 2:08:06 AM5/12/16
to Art, docker-dev

Use the '--rm' option, so that it removes itself after each execution.  It is also advisable to add ExecStartPre statements to 'kill' and 'rm' the container before each execution.  Historically, Docker has not always been successful at honoring the '--rm' option.


--
You received this message because you are subscribed to the Google Groups "docker-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to docker-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Seán C McCord
CyCore Systems, Inc

Art

unread,
May 12, 2016, 9:25:08 AM5/12/16
to docker-dev, art.s...@gmail.com
Unfortunately, the you can't use both together, so I lose the restart capability if I use --rm:
  Conflicting options: --restart and --rm

Seán C. McCord

unread,
May 12, 2016, 11:50:32 AM5/12/16
to Art, docker-dev

Sorry, I presumed you were referring to the systemd restart option, not the Docker restart option.  My opinion is to always have the process controller handle restarts.

Art

unread,
May 17, 2016, 9:00:30 AM5/17/16
to docker-dev
I ended up creating an upstart service to 'docker rm' any pre-existing container, and 'docker run' a new one (with an extra 'docker rm' pre-stop for good measure). It seems to be working as I had intended. Just FYI for anyone finding this thread in the future.

Ochsenbouillon

unread,
Nov 23, 2022, 9:06:16 AM11/23/22
to docker-dev
I run into the same issue and would be grateful to know how you created such a upstart service. Can you share a bit more how you did it? Thanks

clma

unread,
Nov 30, 2022, 12:12:32 PM11/30/22
to docker-dev
Reply all
Reply to author
Forward
0 new messages