- Uninstall Conflicting Packages
Remove any existing Docker packages to avoid conflicts:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
- Update Package Index
Ensure your package index is up-to-date:
sudo apt-get update
- Install Prerequisite Packages
sudo apt-get install ca-certificates curl
- Add Docker’s Official GPG Key
Add Docker’s GPG key to verify package authenticity:
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
- Set Up the Docker Repository
Add Docker’s official repository to your system:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
- Install the Docker packages
Install Docker Engine, CLI, and containerd:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- Verify Docker Installation
Run a test container to confirm Docker is installed correctly:
sudo docker run hello-world
If successful, you’ll see a message confirming Docker’s proper installation.