Learning objectives
By the end of this module, you should be able to:
- Verify Docker CLI, Engine connectivity and Compose availability before starting labs.
- Manage the normal lifecycle of a container.
- Use logs, exec and inspect to understand a running workload.
Install from a supported Docker distribution path
Docker installation differs by platform and Linux distribution. Use Docker’s current official Engine repository instructions on supported Linux distributions, or Docker Desktop where appropriate, rather than copying an old convenience-script command into production.
After installation, verify both the client and Engine with docker version and docker info. For later modules, also verify docker compose version. On Linux, understand that membership in the docker group grants powerful control of the Docker daemon and should be treated as privileged access.
- docker version: client and server versions when Engine is reachable.
- docker info: Engine/storage/runtime overview.
- docker compose version: Compose plugin availability.
- systemctl status docker: useful on systemd-based Docker Engine hosts.
Client and daemon
The docker command is a client. Most commands send API requests to Docker Engine, which owns container and image state. This is why a correctly installed CLI can still fail when the daemon is stopped or the client points at the wrong Docker context.
Lifecycle is explicit
docker run is a convenience that creates and starts a container. You can also create without starting, then start later. A container can be running, stopped and restarted while keeping its writable layer until the container itself is removed.
- create: define a container instance.
- start: run its configured process.
- stop: request graceful termination, then force if necessary.
- rm: delete the container metadata and writable layer.
Observe before changing
docker logs reads the container process output streams, docker inspect returns detailed configuration/state, and docker exec starts an additional process in a running container. These tools form the first troubleshooting layer before you rebuild or replace anything.
Worked examples
See the idea in practice.
Preflight the installation
docker version
docker info
docker compose version
- A healthy Engine reports both client and server information.
- If the CLI exists but cannot reach the daemon, fix service/context/permission issues before proceeding.
- Compose is required for modules 9 and 12.
Name and publish an nginx container
docker run -d --name web -p 8080:80 nginx:alpine
docker ps
- -d runs detached.
- --name gives a stable local name.
- -p 8080:80 publishes host port 8080 to container port 80.
Observe and enter the container
docker logs web
docker inspect web --format '{{.State.Status}} {{.Config.Image}}'
docker exec web nginx -v
- Logs come from the configured container process output.
- inspect exposes Engine metadata.
- exec runs a new command in an already running container.
Hands-on lab
Lab — Manage a web-container lifecycle
Goal: Run nginx, test it, inspect it, stop/restart it and cleanly remove it.
Before you start
- Docker Engine or Docker Desktop installed from a supported source.
- The learner account can run Docker commands intentionally; on Linux, review daemon access permissions rather than blindly using sudo for every command.
- Host port 8080 must be available.
STEP 1Run the Docker preflight
docker version
docker info --format '{{.ServerVersion}} {{.Driver}}'
docker compose version
STEP 2Start nginx
docker run -d --name web-lab -p 8080:80 nginx:alpine
STEP 3Verify from the host
curl -I http://127.0.0.1:8080/
STEP 4Inspect and view logs
docker inspect web-lab --format 'status={{.State.Status}} ip={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
docker logs --tail 20 web-lab
STEP 5Stop and restart
docker stop web-lab
docker ps -a --filter name=web-lab
docker start web-lab
curl -I http://127.0.0.1:8080/
STEP 6Clean up
docker rm -f web-lab
Verify
- HTTP responds while the container is running.
- docker ps -a shows the stopped state after docker stop.
- The same container can be started again before removal.
Expected outcome
- The web server becomes reachable again after restart.
- docker rm -f removes the container.
If it fails
- If port 8080 is busy, choose another host port such as -p 8081:80.
- If curl cannot connect, check docker ps, docker logs and the published Ports column.
Real-world connectionOperations teams inspect state and logs first, then decide whether a container should be restarted, replaced or rebuilt.
Avoid these traps
Common mistakes
- Using docker exec as a permanent configuration-management method.
- Confusing exposed container ports with host-published ports.
- Deleting containers before collecting useful logs or inspection data during an incident.
Knowledge check
Can you explain it without looking back?
Open each answer only after you have tried to answer the question yourself.
1What extra work does docker run perform compared with docker create?
docker run creates the container and then starts it.
2What is docker exec for?
Starting an additional command/process inside an already running container.
3Where should you look first if a detached container exits immediately?
docker ps -a, docker logs and docker inspect for state/exit information.