Now that you know why containers matter, it is time to get Docker running on your own machine. In this lesson you will install Docker on Windows, macOS, or Linux, verify the installation, and practice the handful of commands that make up the daily Docker workflow.
On Windows and macOS the easiest path is Docker Desktop, a bundle that includes the Docker Engine, the command line client, and a management GUI. Download it from docker.com, run the installer, and start the app. On Windows, Docker Desktop uses WSL 2 (Windows Subsystem for Linux) under the hood, so enable WSL 2 if the installer asks.
On Linux you install Docker Engine directly. On Ubuntu or Debian the quick route is the official convenience script:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USERThe last command lets you run docker without sudo. Log out and back in for it to take effect.
Confirm everything works with two commands:
docker --version
docker run hello-worldThe hello-world container prints a message confirming that the client, the daemon, and the registry connection all work. If you see that message, your setup is complete.
docker run nginx # run in the foreground
docker run -d nginx # run detached (background)
docker run -d -p 8080:80 nginx # map host port 8080 to container port 80
docker run -d --name web nginx # give the container a friendly nameThe -d flag detaches the container so your terminal stays free, -p publishes ports, and --name saves you from typing random generated names later.
docker ps # running containers
docker ps -a # all containers, including stopped ones
docker images # images stored locally
docker logs web # view output from the container named webdocker ps is the command you will type most often. Each row shows the container ID, image, status, and port mappings.
docker stop web # graceful stop
docker rm web # remove a stopped container
docker rmi nginx # remove an image from local storageStopped containers still occupy disk space until removed, so make docker rm part of your routine, or use docker run --rm to auto-remove a container when it exits.
Sometimes you want to poke around inside a running container. The exec command runs an extra process in it:
docker exec -it web shThe -it flags give you an interactive terminal. Inside, you can inspect files, check processes, and test commands. Type exit to leave - the container keeps running.
Try this sequence to cement the workflow:
docker run -d -p 8080:80 --name my-nginx nginx
docker ps
docker logs my-nginx
docker stop my-nginx
docker rm my-nginxYou just ran a production-grade web server, checked its logs, and cleaned up - in under a minute.
docker run hello-world verifies your whole setup end to end.run, ps, logs, stop, rm, exec.-d for background containers, -p for port mapping, and --name for readable names.Next up: Images vs Containers, where we dig into the most important distinction in Docker and how layers make images efficient.