On Linux you install Docker Engine directly. On macOS and Windows you install Docker Desktop, which runs the engine inside a small Linux VM. After that the docker commands are the same everywhere.
Ubuntu: don’t use the
docker.iopackage from Ubuntu’s own repositories. It often lags behind and may not include the Compose v2 plugin. The steps below use Docker’s official apt repository.
Remove old or conflicting packages
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)Nothing to run on for this part.
It’s fine if none of these are installed. dpkg will just print warnings.
Install Docker
# 1) Add Docker's GPG key
sudo apt update
sudo apt install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# 2) Add Docker's apt repository
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
# 3) Install Docker Engine, CLI, containerd, Buildx and Compose
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin# Download Docker.dmg for your chip (Apple silicon or Intel) from
# https://docs.docker.com/desktop/setup/install/mac-install/ , then:
cd ~/Downloads
sudo hdiutil attach Docker.dmg
sudo /Volumes/Docker/Docker.app/Contents/MacOS/install
sudo hdiutil detach /Volumes/Docker
open -a Docker# Download "Docker Desktop Installer.exe" from
# https://docs.docker.com/desktop/setup/install/windows-install/ , then:
cd $HOME\Downloads
Start-Process 'Docker Desktop Installer.exe' -Wait -ArgumentList 'install', '--user'
# --user installs per-user (no admin needed). Start Docker Desktop from the Start menu afterwards.Nothing to run on for this part.
On macOS and Windows, open Docker Desktop once and accept the terms. The
dockercommand only works while Docker Desktop is running.
Check the installation
sudo docker run hello-worlddocker run hello-worlddocker run hello-worldUnable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
...
Hello from Docker!
This message shows that your installation appears to be working correctly.Nothing to run on for this part.
Run Docker without sudo
Add yourself to the docker group so you don’t need sudo for every command.
sudo groupadd docker # "already exists" is fine
sudo usermod -aG docker $USER
newgrp docker # or log out and back in
docker run hello-world # now works without sudoNothing to run on for this part.
Security note: Docker’s docs warn that the
dockergroup grants root-level privileges. Only add users you trust.
Run a web server in a container
Start nginx in the background (-d), map port {{HOST_PORT}} on your machine to port 80 in the container (-p), and name it web.
docker run -d -p 8080:80 --name web nginx
docker psCONTAINER ID IMAGE COMMAND STATUS PORTS NAMES
3f2a1b9c8d7e nginx "/docker-entrypoint.…" Up 3 seconds 0.0.0.0:8080->80/tcp webNothing to run on for this part.
Open http://localhost:{{HOST_PORT}} in your browser, or check from the terminal:
curl -I http://localhost:8080curl.exe -I http://localhost:8080HTTP/1.1 200 OK
Server: nginx/...Nothing to run on for this part.
View logs and get a shell inside
docker logs -f web # Ctrl+C to stop following
docker exec -it web sh # type `exit` to leaveNothing to run on for this part.
Clean up
docker stop web
docker rm web
docker image prune # remove unused images (asks first)Nothing to run on for this part.
Troubleshooting
permission denied while trying to connect to the Docker daemon socket (Linux): you’re not in the docker group yet. Redo step 4 and log out and back in.
Cannot connect to the Docker daemon: on Linux, start it with sudo systemctl start docker (and sudo systemctl enable docker.service containerd.service to start it at boot). On macOS/Windows, open Docker Desktop and wait until it says Running.
port is already allocated: something else is using port {{HOST_PORT}}. Pick another port in Your values, or see the recipe Find and kill the process using a port.
Sources
Commands checked against these official sources on 4 Nov 2026. Found something out of date? Open an issue.