Chapter 02
Install Docker and manage containers
Prepare the environment
Install Docker Engine from the official distribution instructions on Linux or Docker Desktop on supported desktops. Ensure the daemon is running and the CLI points to the correct context.
docker --version
docker info
docker run --rm hello-worldHands-on lab: Confirm that hello-world runs successfully.
Quick check: What does docker info validate?
Show answer
That the CLI can contact the selected engine and retrieve its configuration.
Run and inspect containers
Detached mode (-d) runs in the background; --name assigns a readable name; -p publishes a port. Images are pulled when needed.
docker run -d --name web -p 8080:80 nginx:alpine
docker ps
docker logs web
docker inspect webHands-on lab: Open http://localhost:8080 and identify the container ID.
Container lifecycle and cleanup
Use exec for commands inside a running container. Stop gracefully, restart when needed, and remove disposable training containers.
docker exec web nginx -v
docker stop web
docker start web
docker rm -f webHands-on lab: Create and clean up two test containers.
Quick check: Does docker rm delete a named volume?
Show answer
No, named volumes have an independent lifecycle.