Install Docker
This page covers Docker Engine and Docker Compose installation on a Linux VPS. If you are setting up a local development environment on macOS or Windows, see Development setup instead.
The instructions below are adapted from the official Docker documentation (Apache License 2.0).Warning
If your system uses ufw or firewalld, be aware that Docker manages its own iptables rules and will bypass your firewall for container ports. Do not expose port 8080 directly — use NGINX as a reverse proxy instead. See Security hardening for details.
Uninstall conflicting packages
Before installing Docker, remove any unofficial packages that may conflict with it:
sudo apt remove docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc 2>/dev/nullsudo dnf remove docker docker-client docker-client-latest docker-common \
docker-latest docker-latest-logrotate docker-logrotate docker-engine podman runcapt or dnf may report that none of these packages are installed — that is fine.
Install Docker Engine
# Add Docker's official GPG key and repository
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
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
sudo apt update
# Install Docker Engine and Compose plugin
sudo apt install -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin# Add Docker's official GPG key and repository
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/debian/gpg \
-o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update
# Install Docker Engine and Compose plugin
sudo apt install -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-pluginsudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now dockerVerify the installation
sudo docker run hello-world This command pulls a test image and runs it. If Docker is correctly installed, you will see a confirmation message.
Note
On Ubuntu and Debian, the Docker service starts automatically after installation. On RHEL and CentOS, the systemctl enable --now docker command in the previous step handles this. If Docker is not running, start it manually with sudo systemctl start docker.
Allow running Docker without sudo (optional)
By default, Docker requires root privileges. To run Docker commands as your current user:
sudo usermod -aG docker $USER
newgrp docker Warning
Adding a user to the docker group grants effective root-level access to the system. Only do this on a machine you control and trust.