In my docker-compose
file, I’ve set restart: "always"
in order to restart the service if the main program should ever fail. I was expecting that this would mean a clean image (all persistent data was outsourced to volumes or bind mounts). Alas, this is not the case, changes to the main filesystem persist across restarts.
IMHO, this contradicts the main Docker philosophy that fresh containers from an image are cheap and that they should be stateless. Am I wrong here, or is there an option I have overlooked to get the behaviour I am looking for?
A simple example:
docker-compose.yml
:
version: '3'
services:
deb:
image: "debian:latest"
restart: "always"
command: /bin/sleep 120
- Start with
docker-compose up
- Log into container with
docker exec -ti compose_test_deb_1 /bin/bash
- Create footprint with
date > AAA
, then log out. - Wait for the remaining time, after 2 minutes, log in again.
- See if footprint still exists:
cat AAA