Reputation: 411
I'm using the following command to start docker container
# docker run --restart=always -d -p 80:80 image_name
And this means that docker daemon will restart the process if it exits, but it seems that the changes made in the container will remain after the process is restarted. Is there any way to make docker daemon drop all changes on process restart? I mean I want docker daemon to start a fresh container from image instead of restarting only the process.
Upvotes: 2
Views: 1250
Reputation: 506
There is no way with the Docker Engine API.
The best idea is to run the container with --restart=no (default) parameter and use an external process monitor. For example, if you have a RHEL-based OS you can use systemd unit files. You would then control your container as a service.
I commonly do this:
[Unit]
Description=My Service
Requires=docker.service
[Service]
ExecStartPre=/usr/bin/docker create -d --name=container_name image_name
ExecStart=/usr/bin/docker start container_name
ExecStop=/usr/bin/docker stop container_name
ExecStopPost=/usr/bin/docker rm container_name
[Install]
WantedBy=multi-user.target
You can also use docker-compose which has auto recreation options.
Upvotes: 1