103 — Container Lifecycle Management

Master the complete container lifecycle: creating, starting, stopping, restarting, and removing containers. Learn to manage container resources and troubleshoot common issues.

Learning Objectives

1
Understand container states and lifecycle
2
Start, stop, restart, and pause containers
3
Execute commands in running containers
4
Inspect container details and resource usage
5
Manage multiple containers efficiently
Step 1

Understanding container states

Learn about the different states a container can be in: created, running, paused, exited.

Commands to Run

docker run -d --name demo-nginx nginx
docker ps
docker stop demo-nginx
docker ps -a

What This Does

Containers transition through states: created → running → stopped (exited). The `ps` command shows running containers, while `ps -a` shows all containers regardless of state.

Expected Outcome

You'll see the container appear in 'docker ps' with UP status, then after stopping it will show 'Exited' status in 'docker ps -a'.

Pro Tips

  • 1
    Running containers consume resources; stopped containers don't
  • 2
    Stopped containers retain their filesystem and configuration
  • 3
    You can restart stopped containers without losing data

All Steps (0 / 13 completed)