liveBook · Manning

Statefulness

As explained in Learn Docker in a Month of Lunches, Second Edition

A stateful application is an application whose behavior or future results depend on data retained from prior interactions or executions.

A stateful application retains data from earlier interactions or executions, so later behavior depends on what happened before. Unlike stateless applications, its data cannot be treated as disposable with each container. Docker supports stateful apps by storing application data in volumes that survive container replacement. section 6.0 section 6.2

A Docker volume makes statefulness manageable:

  • Create or declare a volume and attach it to the application container. section 6.2
  • Expose the volume as a normal directory, such as /data or C:\data. section 6.2
  • Let the application read and write normally while Docker stores the data independently of the container. section 6.2
  • Attach the same volume to a replacement container so previously stored data remains available after an update. section 6.2

Keeping a to-do list through an update

Run a to-do application with a named volume mounted at its data directory, add items through the web interface, remove the first container, and start a newer container with the same volume. The updated application can still access the original list. section 6.2

Listing 6.1 Part of a multi-stage Dockerfile using a volume
FROM diamol/dotnet-aspnet:2e
WORKDIR /app
ENTRYPOINT ["dotnet", "ToDoList.dll"]

VOLUME /data
COPY --from=builder /out/ .

The Dockerfile declares VOLUME /data, giving the stateful application a persistent storage location when its container starts. section 6.2

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains retained data through Docker volumes, mounts, directories, and container replacement, without detailing application storage internals.
Examples
Demonstrates a containerized to-do list that stores items in /data and retains them across application container updates.
What it assumes
Assumes basic containers and introduces persistent storage through Docker volume creation, attachment, and reuse.
What you can do after
Apply it via Docker volumes to preserve application data while replacing or updating containers.
How it connects
Connects statefulness with stateless applications, containers, Docker volumes, persistent storage, mounts, and container filesystems.

Also explained in

Compare how 14 books explain statefulness →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.