Skip to content
← Free FDE training guides

Free learning / 65-minute container lab

Understand what survives a container replacement

An image is the package; a container is one instance. Follow a pending review through a visual lifecycle, then run a real local API to compare restart, replacement and a mounted volume.

No account needed. Use your own copy for writing and keep the original as a reference.

Engineering lab library / Run locally

See what survives replacement.

Predict the lifecycle, then run the API and compare its actual responses. Keep the Python file and Dockerfile together in a new empty folder.

A real local Docker experiment with synthetic data. Preparation downloads an image; no model, cloud account or public service is used.

  1. Start here / Docker · Actual local containers

    Container lifecycle · local API

    Observe a pending review disappear without a volume and survive replacement when its storage is explicitly retained.

    Local Docker Engine or Desktop · curl · Internet for image preparation

A container is one isolated instance of an application. Its image is the reusable package used to create that instance. Docker is a tool for building images and managing containers; neither is a programming language. Start here before choosing a managed container service or putting an agent worker on a server.

You will run a tiny HTTP API, save a fictional pending review, restart its process, then replace its container. First you will lose the record. Then you will keep it by mounting a named volume. No model, GPU or cloud account is involved.

Allow 60–65 minutes. Use Docker Desktop or a local Docker Engine running Linux containers, a terminal and curl. Image preparation needs internet access and local disk space. After the image is prepared, the experiment runs locally. Optional application checks use Python 3.11+ on your computer.

1. Meet the package, process and storage

UNDERSTAND THE SYSTEM

Follow a review through restart and replacement

An image is a reusable application package. A container is one isolated instance made from it, with its own process and writable layer. Follow a fictional review through restart and replacement on one Docker host; then run the free lab to collect your own observations.

FOLLOW THE WORK

Watch one example, step by step.

6 authored stepsYou control the pace
01 / EXPLORE THE PARTSControls loading · written explanations below
Direction of information or workReturn / feedback

WHAT THIS PART DOES

Code + Dockerfile

The Dockerfile describes how to assemble the image and start the application. This lab packages a Python HTTP API, not a model.

CONNECTED TO
  • Build package: Reusable image
Read the full worked example
  1. 01
    Build the package

    Package the API. There is no running service or pending review yet.

    Prediction: Starting this image creates a new instance, not a copy of a previous instance's later writes.

  2. 02
    Save a review

    Container A starts from image v1. The API saves the fictional R-104 record without a storage mount.

    Observed in the lab: GET /review returns R-104 · pending

  3. 03
    Restart the same container

    The process ends and a new process starts inside A. Its in-memory instance ID changes; A's writable layer still holds the review.

    What survives?: Same container · new process · R-104 remains

  4. 04
    Replace without a volume

    Remove A and create B from the same image. B gets a fresh writable layer. Reusing A's name would not recover A's deleted layer.

    What changed?: New container · same image · review is null

  5. 05
    Save to a named volume

    Mount the new review-data volume at /data in C, then POST R-104 again. The file now lives in the mounted volume.

    Storage decision: The record is in review-data; the process remains replaceable.

  6. 06
    Replace and reconnect storage

    Remove C. Start D with the same review-data volume mounted at /data. Its process is new and its GET request reads the retained record.

    Scope of this evidence: R-104 survives container replacement on this host; backup and host-failure recovery remain untested.

Read the connections in plain English
  1. 01
    Code + Dockerfile → Reusable image

    Bundle the program and runtime into one image.

  2. 02
    Reusable image → Container instance

    Use that image to create a separate container and start its process.

  3. 03
    Container instance → Writable layer

    The pending review goes into the instance's writable layer.

  4. 04
    Container instance → Named volume

    The volume supplies the application's storage path instead of the writable layer.

Check your understanding: A review survived docker restart. Does that prove it will survive docker rm followed by docker run?

No. Restart retains that container's writable layer; removal deletes it. Put the record in explicitly retained storage and verify that the replacement actually reads it. A local volume still needs a separate backup and host-recovery plan.

If you know a class and an object, you already know a useful part of the idea: one reusable definition can produce several separate instances. An image is more concrete than a class: it contains filesystem layers and startup configuration. Each container has its own process environment and a writable layer on top of those image layers.

An image does not contain a running server. A container can be running or stopped. A stopped container still exists; removing it is a separate operation.

PartIn this exerciseWhat to remember
ImagePython, the API file and its start commandA reusable package; creating a new instance does not copy another instance's later writes.
ContainerThe process serving port 8080One instance, with its own lifecycle and writable layer.
Process memoryA freshly generated instance IDLost when the process ends, even when the same container restarts.
Writable layerThe first /data/review.sqlite3Survives stopping and starting that container; disappears when it is removed.
Named volumelockedin-container-101-data mounted at /dataA separate Docker-managed store, reusable by a replacement container.

A virtual machine supplies its own guest operating system and kernel. Linux containers use the host's kernel; Docker Desktop runs them inside a Linux VM on macOS and Windows. A container image must still match a supported operating system and CPU architecture. Packaging an application does not remove those constraints.

Use the visual walkthrough to predict what changes in each step. The diagram contains authored examples. The commands below produce your actual local evidence.

2. Build the small API image

Create a new, empty folder named lockedin-container-101 and open a terminal there. Download both files into it:

Read both files. The API accepts only the fictional record R-104, with status pending. It has no login system and is only for a local exercise. Do not add customer data or publish it as a service.

Create a file called .dockerignore containing exactly:

Text example
*
!fde-container-lab.py

The build context is the folder sent to the builder. This allowlist keeps unrelated files out of that context. Never use your home folder or a folder containing credentials as the build context.

Code example
docker version
docker context show
docker build -f fde-container-lab.Dockerfile -t lockedin-container-lab:1 .
docker image inspect lockedin-container-lab:1 --format '{{.Id}} {{.Config.User}}'

Continue only with your local Docker environment. If Docker is configured for a remote host, change to your approved local environment before running this lab. The first build retrieves the official Python base image pinned in the Dockerfile. A digest identifies fixed image content; the lockedin-container-lab:1 tag is the convenient name you give your new local image. Record the resulting image ID.

The final image runs as numeric user 10001:10001. Only /data needs to be writable by that user. EXPOSE 8080 describes the application port; it does not publish a host port by itself.

If Python is installed on your computer, you can also run python3 fde-container-lab.py --check. These check the application storage behavior, not Docker isolation or durability.

3. Start an instance and save a review

Check docker ps -a --filter name=lockedin-container-101 and docker volume ls --filter name=lockedin-container-101-data first. If either name already belongs to work you need, choose different names throughout this exercise. Do not remove an existing resource to make the example work. If host port 8765 is in use, choose another free port and replace 8765 in every command and URL; leave the other service running.

Code example
docker run --detach --name lockedin-container-101 \
  --publish 127.0.0.1:8765:8080 \
  --memory 128m --cpus 0.5 --pids-limit 32 \
  --cap-drop ALL --security-opt no-new-privileges \
  lockedin-container-lab:1
curl --fail http://127.0.0.1:8765/healthz
curl --fail http://127.0.0.1:8765/review
curl --fail --header 'Content-Type: application/json' \
  --data '{"id":"R-104","status":"pending"}' \
  http://127.0.0.1:8765/review

After each start or restart, let the server start before making the next request. If a request arrives too early, retry that request after the container is running. A persistent connection failure needs docker logs lockedin-container-101, not a bigger instance.

The first review response has review: null; the POST response contains R-104. The instance field identifies the current process, not a user or a model. Save its actual value.

Read the port mapping from left to right: 127.0.0.1 restricts the published listener to this computer; 8765 is the host port; 8080 is the container's port. Inside its network namespace the server listens on 0.0.0.0 so the forwarded request can reach it. These two addresses serve different purposes.

The resource limits bound this lab's process; they do not make the API an authenticated production service. /healthz only proves this process can answer. It does not prove that a pending review was retained.

4. Restart, then replace without a volume

Predict both the instance ID and the saved review before running each command.

Code example
docker restart --timeout 1 lockedin-container-101
curl --fail http://127.0.0.1:8765/review
docker inspect lockedin-container-101 --format '{{.Id}} {{.Image}}'

The process instance ID changes. The record remains. Restarting the same container kept its writable layer. A passing restart test alone has not proved that a new release can replace this container safely.

Now stop and remove only the container you created. This deliberately destroys its lab record:

Code example
docker stop --timeout 1 lockedin-container-101
docker rm lockedin-container-101
docker run --detach --name lockedin-container-101 \
  --publish 127.0.0.1:8765:8080 \
  --memory 128m --cpus 0.5 --pids-limit 32 \
  --cap-drop ALL --security-opt no-new-privileges \
  lockedin-container-lab:1
curl --fail http://127.0.0.1:8765/review
docker inspect lockedin-container-101 --format '{{.Id}} {{.Image}}'

The container ID is new; the image ID is the same. The review is now null. Reusing a name did not reuse the removed container's writable layer. The image never contained your later POST.

5. Replace the process and keep the review

Stop and remove that empty lab container. Create a new, explicitly named volume and mount it at the path the application uses:

Code example
docker stop --timeout 1 lockedin-container-101
docker rm lockedin-container-101
docker volume create lockedin-container-101-data
docker run --detach --name lockedin-container-101 \
  --publish 127.0.0.1:8765:8080 \
  --memory 128m --cpus 0.5 --pids-limit 32 \
  --cap-drop ALL --security-opt no-new-privileges --read-only \
  --mount type=volume,source=lockedin-container-101-data,target=/data \
  lockedin-container-lab:1
curl --fail --header 'Content-Type: application/json' \
  --data '{"id":"R-104","status":"pending"}' \
  http://127.0.0.1:8765/review
docker inspect lockedin-container-101 --format '{{json .Mounts}}'

The explicit mount supplies the writable /data directory; the rest of the container filesystem is now read-only. Docker initializes this new empty volume from the image's /data directory, including its ownership. An existing volume may have different permissions; do not fix that by running your application as root.

Remove only this lab container, keeping the volume:

Code example
docker stop --timeout 1 lockedin-container-101
docker rm lockedin-container-101

Run the same mounted docker run command above again, then request /review. The process and container IDs change; R-104 remains. Record the volume name and mount destination as well as the response. Naming a volume is not enough: the replacement must mount it at the path the application actually reads.

A named volume on one Docker host is not a backup, a cross-region replica or a highly available database. Losing that host or deleting its volume can still lose the review. This exercise proves replacement behavior on one local host only.

5a. Diagnose a healthy API reading the wrong volume

Continue after section 5, while the original lab volume still holds R-104. This controlled mistake changes the mount source, not the image or application. Predict the two HTTP responses before replacing anything. Preserve the original volume and do not POST another record during this diagnostic.

First inspect whether lockedin-container-101-empty already exists. If it does, choose a different unused name for this new volume throughout the experiment; do not remove somebody else's data. Replace the example container, volume and port names below with your own if you changed them earlier.

Code example
docker volume ls --filter name=lockedin-container-101-empty
docker stop --timeout 1 lockedin-container-101
docker rm lockedin-container-101
docker volume create lockedin-container-101-empty
docker run --detach --name lockedin-container-101 \
  --publish 127.0.0.1:8765:8080 \
  --memory 128m --cpus 0.5 --pids-limit 32 \
  --cap-drop ALL --security-opt no-new-privileges --read-only \
  --mount type=volume,source=lockedin-container-101-empty,target=/data \
  lockedin-container-lab:1

Wait for startup, then observe both the process and its saved work:

Code example
curl --fail http://127.0.0.1:8765/healthz
curl --fail http://127.0.0.1:8765/review
docker inspect lockedin-container-101 --format '{{.Id}} {{.Image}} {{json .Mounts}}'

Health answers HTTP 200, and the review response also answers 200 with review: null. Read the source of /data in .Mounts: it is the new empty volume. The program opened a different database at the same path. /healthz only returns process information; it never reads the review. A healthy process is compatible with the wrong data selection.

Now stop and remove only this lab container, then repeat the mounted docker run command in section 5 with the original lockedin-container-101-data source. Read /review again without writing a new record, and inspect the mount:

Selected source at /dataHealth responseReview responseWhat this tells you
Original volume after saving200R-104 pendingThis process can read the saved record.
Different fresh volume200nullThe selected store has no review; the original was not removed.
Original volume reconnected200R-104 pendingThe original record survived this detour on this host.

The image ID stays fixed, while every replacement creates a new container and process ID. Your actual generated IDs will differ from another learner's. Record those identities and both mount sources. Do not replace the original store or re-save a record merely to produce a reassuring response.

This is reconnection, not restoration from a backup: the original store remained on the same host. A database restore, host-loss recovery and simultaneous writers need separate tests. A changed mount destination or LAB_DATA_DIR can also change which file is opened; trace the complete source → mount → application path rather than judging a familiar path string alone.

After section 7's normal cleanup, remove the extra empty volume only if you created it in this section, using the exact name you selected:

Code example
docker volume rm lockedin-container-101-empty

UNDERSTAND THE SYSTEM

A healthy process can be reading the wrong store.

Follow the same image through three local Docker runs. This authored display uses short volume aliases; collect your actual container IDs, mount sources and HTTP responses in the workbook. It does not start containers or prove cloud recovery.

FOLLOW THE WORK

Watch one example, step by step.

3 authored stepsYou control the pace
01 / EXPLORE THE PARTSControls loading · written explanations below
Direction of information or workReturn / feedback

WHAT THIS PART DOES

Run the API

A new container starts a new process from the same image. Its generated instance ID identifies this process lifetime, not the stored review or a user.

CONNECTED TO
  • Resolve path: Select the mount
  • Health check: Check the process
Read the full worked example
  1. 01
    Read the original volume

    Save R-104 in the original named volume. Both handlers answer, and the review handler reads the pending record. Retain the mount source as part of the evidence.

    LOCAL DOCKER · ORIGINAL: Health 200 · review R-104 · original volume

  2. 02
    Mount a different empty volume

    Remove only the container, retaining the original volume. Start from the same image with a different fresh volume at /data. Health still answers 200, but the review is null. The original volume has not been removed; this response alone does not prove what it contains.

    LOCAL DOCKER · DIFFERENT STORE: Health 200 · review null · different volume

  3. 03
    Reconnect the original volume

    Remove the empty-view container and mount the original source at /data again. The new process reads R-104. This verifies that the original record survived the detour on this host. No restore from backup or replication occurred.

    LOCAL DOCKER · RECONNECTED: Health 200 · review R-104 · original volume

Read the connections in plain English
  1. 01
    Run the API → Select the mount

    Follow the configured storage path to its mount source.

  2. 02
    Select the mount → Open the selected store

    Read the SQLite file from the selected volume.

  3. 03
    Open the selected store → Read the saved work

    Inspect the saved record, independently of process health.

  4. 04
    Run the API → Check the process

    This handler checks neither retained work nor storage selection.

Check your understanding: Did reconnecting the volume restore a backup?

No. It selected the original store, which had remained on this Docker host. A backup restore, host-loss recovery and multi-host service require separate mechanisms and evidence.

6. Carry the decision into a cloud deployment

Hosting choiceWhat runs your imageWhere the pending review should live
VM running DockerYou manage the VM, container runtime and serviceExplicit durable storage, with a tested backup and recovery plan.
Managed container serviceThe provider manages more of the runtimeA suitable external database or a documented supported persistent mount.
KubernetesA cluster schedules container workloads into podsA state service or deliberately configured persistent storage; a pod's replacement is expected.

Cloud Run, Amazon ECS and Azure Container Apps are examples of container hosting services with different operating models. Do not assume their filesystem behavior matches this local Docker host. Consult the chosen service's storage and lifecycle contract before carrying the design over.

Explain this to a receiving engineer: "The model or worker may be replaceable, but a human's pending review must still exist after deployment." Keep these observations:

  1. One image ID and the container IDs before and after replacement.
  2. The actual response after restart, replacement without a mount and replacement with a mount.
  3. A diagram placing code, process memory, durable reviews and runtime credentials in different locations.
  4. One remaining failure case, such as losing the storage host, and the recovery test you would need.

Change the design on paper: two workers must read the same review from different hosts. Explain why a local named volume alone no longer satisfies the requirement. Choose a storage service and state the concurrency, access and recovery behavior you would need to verify.

7. Clean up only this experiment

Keep your observation notes, then stop and remove the lab container. The following volume removal deliberately deletes the synthetic record:

Code example
docker stop --timeout 1 lockedin-container-101
docker rm lockedin-container-101
docker volume rm lockedin-container-101-data
docker image rm lockedin-container-lab:1
docker ps -a --filter name=lockedin-container-101
docker volume ls --filter name=lockedin-container-101-data

Use the names you actually chose. If a resource is already absent, inspect rather than widening cleanup. Never use a global prune command for this lab. The downloaded base image can remain in Docker's cache for reuse.

8. Read the source explanations

Original LockedIn Labs exercise. Docker and Cloud Run references rechecked 25 October 2026; AWS and Azure references last checked 21 October 2026:

Continue with Containers 101: package, run and retain work for the full explanation, knowledge checks and Explain/Debug/Design rehearsals. Then use the existing advanced deployment lesson for durable jobs, bounded retries and deployment handoff. Completing this exercise is practice evidence, not a vendor certification or a production-readiness approval.

Before you move on

Keep the evidence of your work.

  • The image and container identities from the actual experiment.
  • Responses after restart, replacement without storage and replacement with a volume.
  • A storage diagram and one host-recovery failure still to test.

Keep these in your own working copy. Reading this page does not save work or record completion.

Suggested next free session

Follow a job from accepted to finished

Understand delivery and acknowledgements after process replacement. This is a suggested sequence; choose the practice that addresses your current gap.

Open the next free guide

Free account

Give your practice a home.

Try a role exercise with account drafts and a downloadable worksheet. Keep the files you made in this guide in your own working copy.

Create a free learning account

Guided training · by application

Build toward a program.

Request structured lessons and a training seat. Scope, schedule, feedback arrangements and tuition are confirmed in writing before you commit.

Explore a training application
Have Academy access?

Use your existing training seat to open worked explanations and practice in the related lesson. Creating a free account does not grant a seat.

Open the related Academy lesson →
Back to top ↑