A container has a lifecycle: created, running, paused, exited and removed. Docker can inspect process logs, execute additional commands in a running container and configure restart policies. Persistent data should be stored outside the disposable writable layer. The exercises use small local containers and scoped names to avoid touching other applications.
Browser-based DevOps simulations. Commands, interfaces, logs and infrastructure states are illustrative; no Jenkins, Docker, Git hosting or Kubernetes operation is executed.
1. Create, start, stop and remove
docker create prepares a container without launching its process; docker start launches it. docker stop requests termination and may force termination after a timeout. docker rm normally removes stopped containers; it does not remove the source image.
Why this example? Compare leaving a stopped container with removing it.
Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
Concept flowchart
Swipe diagram horizontally if needed to read every label.
The diagram shows possible execution paths and expected outcomes. Blue identifies the current step, green marks completed operations, and red marks failure paths.
Current stepSelected path / resultDecision
Architecture view Live teaching state
Why this step happens
See all steps in this scenario
Commands and configuration
Simulated terminal outputConsole
Data operationsCompact blocks
CurrentResultError / rejected
Execution details
Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.
What this animation explains
docker create prepares a container without launching its process; docker start launches it. docker stop requests termination and may force termination after a timeout. docker rm normally removes stopped containers; it does not remove the source image.
Try and observe
Watch the lifecycle and the effect on docker ps -a.
2. Foreground, detached and logs
A foreground container attaches the CLI to its streams, while -d starts detached and returns the container ID. docker logs reads retained stdout/stderr. A process that exits immediately does not stay running simply because it was detached.
Why this example? Compare a one-shot detached process and a long-lived nginx process.
Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
Concept flowchart
Swipe diagram horizontally if needed to read every label.
The diagram shows possible execution paths and expected outcomes. Blue identifies the current step, green marks completed operations, and red marks failure paths.
Current stepSelected path / resultDecision
Architecture view Live teaching state
Why this step happens
See all steps in this scenario
Commands and configuration
Simulated terminal outputConsole
Data operationsCompact blocks
CurrentResultError / rejected
Execution details
Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.
What this animation explains
A foreground container attaches the CLI to its streams, while -d starts detached and returns the container ID. docker logs reads retained stdout/stderr. A process that exits immediately does not stay running simply because it was detached.
Try and observe
Inspect process lifetime and recorded logs.
3. Exec and inspect
docker exec launches an additional process inside an already-running container. It does not restart a stopped container. docker inspect works on existing stopped or running containers and shows configuration and runtime state.
Why this example? Try executing a command before and after stopping a container.
Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
Concept flowchart
Swipe diagram horizontally if needed to read every label.
The diagram shows possible execution paths and expected outcomes. Blue identifies the current step, green marks completed operations, and red marks failure paths.
Current stepSelected path / resultDecision
Architecture view Live teaching state
Why this step happens
See all steps in this scenario
Commands and configuration
Simulated terminal outputConsole
Data operationsCompact blocks
CurrentResultError / rejected
Execution details
Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.
What this animation explains
docker exec launches an additional process inside an already-running container. It does not restart a stopped container. docker inspect works on existing stopped or running containers and shows configuration and runtime state.
Try and observe
See that inspect can still work when exec is rejected.
4. Restart policies
Restart policies govern automatic restart after exit. on-failure restarts when the process exits with nonzero status, within configured retry limits. A normal exit is not restarted by on-failure. Manual stopping and daemon restarts have separate rules.
Why this example? Compare exit code zero with nonzero using on-failure:2.
Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
Concept flowchart
Swipe diagram horizontally if needed to read every label.
The diagram shows possible execution paths and expected outcomes. Blue identifies the current step, green marks completed operations, and red marks failure paths.
Current stepSelected path / resultDecision
Architecture view Live teaching state
Why this step happens
See all steps in this scenario
Commands and configuration
Simulated terminal outputConsole
Data operationsCompact blocks
CurrentResultError / rejected
Execution details
Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.
What this animation explains
Restart policies govern automatic restart after exit. on-failure restarts when the process exits with nonzero status, within configured retry limits. A normal exit is not restarted by on-failure. Manual stopping and daemon restarts have separate rules.
Try and observe
Observe bounded retries for the nonzero case.
5. Bind mount versus named volume
A bind mount maps an explicit host path into the container, while a named volume is managed by Docker. A read-only mount prevents writes through that mount. Choose dedicated paths and avoid mounting sensitive host directories.
Why this example? Compare a read-only and read-write named volume.
Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
Concept flowchart
Swipe diagram horizontally if needed to read every label.
The diagram shows possible execution paths and expected outcomes. Blue identifies the current step, green marks completed operations, and red marks failure paths.
Current stepSelected path / resultDecision
Architecture view Live teaching state
Why this step happens
See all steps in this scenario
Commands and configuration
Simulated terminal outputConsole
Data operationsCompact blocks
CurrentResultError / rejected
Execution details
Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.
What this animation explains
A bind mount maps an explicit host path into the container, while a named volume is managed by Docker. A read-only mount prevents writes through that mount. Choose dedicated paths and avoid mounting sensitive host directories.
Try and observe
Inspect the write result in the container.
6. Resource and health inspection
docker stats shows live CPU and memory measurements. A Docker health check runs a configured command and reports starting, healthy or unhealthy. An unhealthy result alone does not automatically restart a plain Docker container.
Why this example? Select whether a configured health probe succeeds or fails.
Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
Concept flowchart
Swipe diagram horizontally if needed to read every label.
The diagram shows possible execution paths and expected outcomes. Blue identifies the current step, green marks completed operations, and red marks failure paths.
Current stepSelected path / resultDecision
Architecture view Live teaching state
Why this step happens
See all steps in this scenario
Commands and configuration
Simulated terminal outputConsole
Data operationsCompact blocks
CurrentResultError / rejected
Execution details
Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.
What this animation explains
docker stats shows live CPU and memory measurements. A Docker health check runs a configured command and reports starting, healthy or unhealthy. An unhealthy result alone does not automatically restart a plain Docker container.
Try and observe
Compare running process state with independent health status.
Command and configuration reference
Use these commands and settings with the corresponding installed tools in a disposable practice environment.
Command / setting
Why and when to use it
docker create --name web-lab nginx:alpine
Create, start, stop and remove — Compare leaving a stopped container with removing it.
docker run -d --name msg-lab alpine echo hello
Foreground, detached and logs — Compare a one-shot detached process and a long-lived nginx process.
docker run -d --name exec-lab nginx:alpine
Exec and inspect — Try executing a command before and after stopping a container.
docker run --name retry-lab --restart=on-failure:2 alpine sh -c "exit 0"
Restart policies — Compare exit code zero with nonzero using on-failure:2.
docker volume create write-lab
Bind mount versus named volume — Compare a read-only and read-write named volume.
Resource and health inspection — Select whether a configured health probe succeeds or fails.
Worked practical examples
Follow the procedures in an isolated practice environment. Configuration snippets may require an existing project, build tools, credentials, images or cluster objects as indicated.
2. Predict the final state for Web server in “Foreground, detached and logs”. Which operation explains it?
Running process remains present Result: web-lab Up.
3. Predict the final state for Stopped in “Exec and inspect”. Which operation explains it?
Start container before using exec Result: Inspect remains available.
Hands-on practice and assessment
Hands-on challenge
Practice with uniquely named nginx and Alpine containers, inspect state, stop and start them, and remove only your lab containers.
Edit this command/configuration scratchpad. Review prerequisites and run only in your own isolated practice environment; the browser never executes commands.
Quick assessment
Official documentation
Use the documentation for your installed tool versions and platform.
Use a local disposable practice environment and verify the active context, account, repository and names before running commands. Examples use Java 21, Maven 3.9, Jenkins Pipeline, Docker Engine and standard Kubernetes APIs. Logs and interfaces are educational reconstructions; versions, permissions, resources and real results can differ. No real deployments, credentials or network operations run in this page.