How to install Docker on Linux
Topic: Containers core
Summary
Install Docker Engine on Debian, Ubuntu, or RHEL using the official Docker repository. Add your user to the docker group so you can run containers without root. Use this when setting up a host for containers or when you need a specific Docker version.
Intent: How-to
Quick answer
- Debian/Ubuntu: add apt.docker.com repo; apt install docker-ce docker-ce-cli containerd.io. RHEL: add yum.docker.com repo; dnf install docker-ce docker-ce-cli containerd.io. Start and enable: systemctl start docker; systemctl enable docker.
- Add user to docker group: usermod -aG docker $USER; log out and back in (or newgrp docker). Verify: docker run hello-world. Rootless optional: install docker-rootless-extras and run dockerd-rootless.
- Compose: apt install docker-compose-plugin or dnf install docker-compose-plugin; then docker compose version. Do not use standalone docker-compose if plugin is available.
Steps
-
Add repository
Follow docs.docker.com for your distro: add Docker GPG key and repo. Debian: apt update; apt install docker-ce docker-ce-cli containerd.io. RHEL: dnf install docker-ce docker-ce-cli containerd.io.
-
Start and enable
systemctl start docker; systemctl enable docker. systemctl status docker. Optional: configure storage driver and log driver in /etc/docker/daemon.json.
-
Add user to docker group
usermod -aG docker myuser. User must log out and back in (or newgrp docker) for group to apply. Verify: docker run hello-world (no sudo).
-
Install Compose plugin
apt install docker-compose-plugin (or dnf). docker compose version. Use docker compose up -d (with space) for Compose v2.
Summary
Install Docker Engine from the official repo; start and enable the service; add users to the docker group. Use this to prepare a host for running containers.
Prerequisites
- Root or sudo on a Linux host.
Steps
Step 1: Add repository
Add the Docker repository for your distro; install docker-ce, docker-ce-cli, and containerd.
Step 2: Start and enable
Start and enable the Docker service; optionally configure daemon.json.
Step 3: Add user to docker group
Add the user to the docker group so they can run containers without root; re-login to apply.
Step 4: Install Compose plugin
Install the docker-compose plugin; verify with docker compose version.
Verification
- docker run hello-world succeeds; docker compose version works; user can run docker without sudo.
Troubleshooting
Permission denied — Ensure user is in docker group and has logged out and back in. Cannot connect to daemon — Docker service may not be running; check systemctl status docker.