Reputation: 83
Let's consider following example:
version: '3'
services:
some_service:
build: .
restart: unless-stopped
This docker-compose
works properly, however during restart it preserve changes (in filesystem) introduced in previous running (before restart).
How to configure restart-policy to force loosing changes in fileysystem? Is it possible to change restart-policy on running container?
Upvotes: 2
Views: 3044
Reputation: 12089
When you docker-compose up
, you create "containers", they have their own file system. And when you restart a container, it's still the same container with the same file system. So what you have is expected.
If you want a fresh restart, you need to do docker-compose down
to remove containers and then up
to create new ones.
You can't change restart policy on a running container.
EDIT
@BMitch You can change restart policy with docker update
docker update --restart=on-failure container_id
Upvotes: 0
Reputation: 263577
docker-compose
deploys containers with a configuration to be managed by the docker engine. That restart policy is applied to the container, which is handled by the engine. When the engine restarts a container, the previous container state is maintained. The only exception is a tmpfs filesystem mount inside your container which will reset to an empty directory.
However, if your service is managed by swarm mode instead of docker-compose, the default changes to recreate any failed containers instead of just restarting them. You can configure a single node swarm cluster with:
docker swarm init
And then you can deploy your service with:
docker stack deploy -c docker-compose.yml your-app
Note that with swarm mode you do not need to define the restart policy. Swarm mode will correct any difference from the target state, whether the container exits, fails a health check, or gets deleted, the response will be to deploy a new container.
Upvotes: 3