Install Docker and run hello-world

Docker · Essentials · 8 min

You need a working client and daemon before anything else, and knowing which is which helps debugging.

Docker has two parts: the `docker` CLI you type commands into, and the Docker daemon (dockerd) that actually builds images and runs containers. The CLI talks to the daemon over an API, by default through the Unix socket /var/run/docker.sock.

How to install:

  • macOS and Windows: Docker Desktop, which bundles the CLI, a Linux VM running the daemon, Compose, BuildKit and a GUI. On Windows it uses WSL 2.
  • Linux servers: Docker Engine from Docker's own apt/dnf repository (the distribution's packages are often old), following the install page for your distribution. Docker Desktop for Linux also exists.

Check the installation with docker version. It prints a Client and a Server section; if the server part errors with "Cannot connect to the Docker daemon", the CLI works but the daemon isn't running or you lack permission to its socket. docker info shows details such as storage driver, number of containers and images.

Then run the classic test, docker run hello-world. Docker looks for the hello-world image locally, pulls it from Docker Hub, creates a container from it, runs it (it prints a message and exits), and you're done.

On Linux, Docker commands need root by default. Adding yourself to the docker group (sudo usermod -aG docker $USER, then log in again) removes the sudo, but understand what that means: access to the Docker socket is equivalent to root on the host, because you can start a container that mounts /. Rootless mode, covered later, avoids this.

Example

docker version
# Client: Version: 29.x ...
# Server: Docker Engine - Community  Version: 29.x ...

docker run hello-world
# Unable to find image 'hello-world:latest' locally
# latest: Pulling from library/hello-world
# Hello from Docker!

docker info --format '{{.ServerVersion}} {{.Driver}}'

# Linux: run docker without sudo (grants root-equivalent access!)
sudo usermod -aG docker "$USER" && newgrp docker

Remember

  • The docker CLI is a client; dockerd does the work behind an API socket
  • docker version shows both; a missing Server section means no daemon access
  • Membership of the docker group is root-equivalent

Watch out for

  • Installing the distribution's old docker.io package and then missing current features like BuildKit defaults or Compose v2.

Check yourself

  1. docker version prints the Client section, then 'Cannot connect to the Docker daemon'. What's wrong?
  2. Why is adding a user to the docker group a security decision?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: docs.docker.com/get-started/get-docker/

Builds on

Nothing: this is a foundation.

Unlocks