A volume
This page adds a named volume: a directory that belongs to the deployment rather than to a container, so what a service writes there outlives the container. A container is replaced whenever its image or settings change; anything it kept in its own filesystem goes with it.
guestbook gets a counter, counter, a Redis that keeps the number of visits
in /data. Start it on Redis 7.2, with data mounted at /data.
--appendonly yes makes Redis write every change to disk there.
services: web: image: nginx:1.27-alpine expose: - "80" volumes: - ./site:/usr/share/nginx/html:ro x-shc-primary: true api: image: traefik/whoami:v1.10 command: ["--port", "8080", "--name", "guestbook-api"] expose: - "8080" x-shc-path: /api x-shc-path-strip: true counter: image: redis:7.2-alpine command: ["redis-server", "--appendonly", "yes"] expose: - "6379" volumes: - data:/datavolumes: data:$ shc update guestbook...Count three visits.
$ shc exec -s guestbook -S counter -- redis-cli incr visits1$ shc exec -s guestbook -S counter -- redis-cli incr visits2$ shc exec -s guestbook -S counter -- redis-cli incr visits3SHC makes each named volume a directory of the deployment, mounts/<name>,
on the node that runs it, and binds it into the container.
$ ls -1 /var/lib/shc/deployments/prod/guestbook/prod/mountsdata$ ls -1 /var/lib/shc/deployments/prod/guestbook/prod/mounts/dataappendonlydirNow upgrade Redis to the newest 7. A new image means a new container: the old one is removed with everything in its own filesystem.
services: web: image: nginx:1.27-alpine expose: - "80" volumes: - ./site:/usr/share/nginx/html:ro x-shc-primary: true api: image: traefik/whoami:v1.10 command: ["--port", "8080", "--name", "guestbook-api"] expose: - "8080" x-shc-path: /api x-shc-path-strip: true counter: image: redis:7-alpine command: ["redis-server", "--appendonly", "yes"] expose: - "6379" volumes: - data:/datavolumes: data:$ shc update guestbook...$ shc exec -s guestbook -S counter -- redis-server --version...The new container read the count from the volume.
$ shc exec -s guestbook -S counter -- redis-cli get visits3Next: A healthcheck.