teluzia.Cloud Engineer · Day 99
CHAPTER 15 · DOCKER AND CONTAINERS

Container fundamentals and Docker CLI

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

An image is a packed lunch recipe; a container is one person’s prepared lunch, with its own runtime changes. An image contains filesystem layers and configuration. A container starts a process from that image with isolation boundaries. Containers share a host kernel rather than each carrying a full independent virtual-machine kernel. Stopping a container stops its process but does not delete the image. docker run creates and starts a container; ps lists running containers and ps -a includes stopped ones. logs shows captured process output. inspect reveals configuration and status. Learn lifecycle commands before using automated cleanup so you can identify exactly which practice object is being changed.

Think of it this way

An image is a packed lunch recipe; a container is one person’s prepared lunch, with its own runtime changes.

TOPIC 01 / 03Step by step

Images, containers, and processes

An image contains filesystem layers and configuration. A container starts a process from that image with isolation boundaries. Containers share a host kernel rather than each carrying a full independent virtual-machine kernel. Stopping a container stops its process but does not delete the image. For example, two containers can start from nginx:alpine while keeping separate writable layers and runtime identities.

WORKED EXAMPLE
Two containers can start from nginx:alpine while keeping separate writable layers and runtime identities.

Pulling an image obtains a packaged filesystem and configuration. Starting a container uses that image to create an isolated process environment with its own writable layer. The main process runs until it exits or is stopped; a stopped container is still a stored container object until removal. The image can remain available for later containers.

An image is a reusable starting artifact. A container is a runtime instance. The writable layer stores changes specific to that instance. Containers share the underlying host kernel rather than each booting an entirely independent operating system. This makes them lightweight but limits compatibility and isolation assumptions. Several containers from one image do not share process memory automatically. Persistent business data should use deliberately managed storage, not rely on the lifetime of that writable layer. Removing a container can remove its local changes without removing the image or separately retained volumes.

Why this matters

Two containers can start from nginx:alpine while keeping separate writable layers and runtime identities.

A common trap

Do not overlook this operational distinction: Stopping a container stops its process but does not delete the image.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Images, containers, and processes

An image contains filesystem layers and configuration. A container starts a process from that image with isolation boundaries. Containers share a host kernel rather than each carrying a full independent virtual-machine kernel. Stopping a container stops its process but does not delete the image. For example, two containers can start from nginx:alpine while keeping separate writable layers and runtime identities.

WORKED EXAMPLE
Two containers can start from nginx:alpine while keeping separate writable layers and runtime identities.

Pulling an image obtains a packaged filesystem and configuration. Starting a container uses that image to create an isolated process environment with its own writable layer. The main process runs until it exits or is stopped; a stopped container is still a stored container object until removal. The image can remain available for later containers.

An image is a reusable starting artifact. A container is a runtime instance. The writable layer stores changes specific to that instance. Containers share the underlying host kernel rather than each booting an entirely independent operating system. This makes them lightweight but limits compatibility and isolation assumptions. Several containers from one image do not share process memory automatically. Persistent business data should use deliberately managed storage, not rely on the lifetime of that writable layer. Removing a container can remove its local changes without removing the image or separately retained volumes.

Why this matters

Two containers can start from nginx:alpine while keeping separate writable layers and runtime identities.

A common trap

Do not overlook this operational distinction: Stopping a container stops its process but does not delete the image.

CLI lifecycle and inspection

docker run creates and starts a container; ps lists running containers and ps -a includes stopped ones. logs shows captured process output. inspect reveals configuration and status. Learn lifecycle commands before using automated cleanup so you can identify exactly which practice object is being changed. For example, docker stop lesson99 stops the named practice container; docker rm lesson99 removes that container after it stops.

WORKED EXAMPLE
docker stop lesson99 stops the named practice container; docker rm lesson99 removes that container after it stops.

A detached container command returns an ID, but the application immediately exits due to missing configuration. docker ps shows nothing running, while docker ps -a reveals the stopped object and exit status. Logs may show the startup error. Inspecting the object's state distinguishes this from a daemon connectivity problem or missing image.

Detached execution returns control while the process runs. Exit status communicates how the main process ended. Container inspection reveals configuration and runtime metadata. Use names for identifiable practice scope, then inspect status, logs, port mappings, and mounts before restarting. Repeatedly launching new containers can leave many stopped objects and obscure the first useful failure. Logs depend on the application's stdout/stderr and configured logging behavior; an empty log does not prove the process did useful work. Stop and remove only known practice objects rather than running broad cleanup commands against unrelated workloads.

Why this matters

docker stop lesson99 stops the named practice container; docker rm lesson99 removes that container after it stops.

A common trap

Do not overlook this operational distinction: Learn lifecycle commands before using automated cleanup so you can identify exactly which practice object is being changed.

Isolation limits and safe defaults

Container isolation is not absolute security. Privileged mode, sensitive host mounts, root execution, and the Docker daemon’s authority can broaden impact. Publish ports deliberately, use trusted images, and avoid mounting host credentials or the Docker socket into untrusted workloads. For example, bind a learning server to 127.0.0.1 on the host instead of exposing it on every network interface.

WORKED EXAMPLE
Bind a learning server to 127.0.0.1 on the host instead of exposing it on every network interface.

A container receives a bind mount of the host's credential directory and runs in privileged mode. Even if its image looks like a harmless utility, the runtime permissions expose host resources it otherwise could not reach. Its effective risk depends on launch configuration and daemon authority, not solely on image size or package count.

Isolation limits access between workloads. Privileged mode broadens capabilities and device access. A host mount exposes selected filesystem paths directly. Avoid sharing the Docker socket with untrusted code because daemon control can lead to substantial host authority. Use non-root identities where supported, scoped read-only mounts, explicit resource limits, and trusted maintained images. Publishing a port on localhost reduces external exposure for local exercises but is not complete application authorization. Containers can improve packaging consistency while still running vulnerable or malicious software, so assess artifact provenance and runtime access together.

Why this matters

Bind a learning server to 127.0.0.1 on the host instead of exposing it on every network interface.

A common trap

Do not overlook this operational distinction: Publish ports deliberately, use trusted images, and avoid mounting host credentials or the Docker socket into untrusted workloads.

KEEP THESE WITH YOU

Today’s takeaways

Images, containers, and processes: An image contains filesystem layers and configuration. A container starts a process from that image with isolation boundaries. Containers share a host kernel rather than each carrying a full independent virtual-machine kernel. Stopping a container stops its process but does not delete the image.

CLI lifecycle and inspection: docker run creates and starts a container; ps lists running containers and ps -a includes stopped ones. logs shows captured process output. inspect reveals configuration and status. Learn lifecycle commands before using automated cleanup so you can identify exactly which practice object is being changed.

Isolation limits and safe defaults: Container isolation is not absolute security. Privileged mode, sensitive host mounts, root execution, and the Docker daemon’s authority can broaden impact. Publish ports deliberately, use trusted images, and avoid mounting host credentials or the Docker socket into untrusted workloads.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed