Docker is a platform that allows you to automate the deployment, scaling, and management of applications inside lightweight containers. To install Docker on Ubuntu, follow these steps:

Prerequisites
Before installing Docker, ensure you have a 64-bit version of one of these Ubuntu versions:
- Ubuntu Noble 24.04 (LTS)
- Ubuntu Jammy 22.04 (LTS)
- Ubuntu Focal 20.04 (LTS)
Additionally, uninstall any conflicting packages such as docker.io, docker-compose, docker-compose-v2, docker-doc, podman-docker, containerd, and runc.
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
Installation Methods
There are several ways to install Docker on Ubuntu:
Using the apt Repository
- Set up Docker’s apt repository:
sudo apt-get update
sudo apt-get install 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
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
Install Docker packages:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Verify the installation:
sudo docker run hello-world
Using a Convenience Script
Docker provides a convenience script for quick installation. This method is not recommended for production environments but is useful for development and testing.
- Download and run the script:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Manual Installation
If you cannot use Docker’s apt repository, you can download the .deb files and install them manually.
- Download the necessary .deb files from Docker’s website.
- Install the packages:
sudo dpkg -i ./containerd.io_<version>_<arch>.deb ./docker-ce_<version>_<arch>.deb ./docker-ce-cli_<version>_<arch>.deb ./docker-buildx-plugin_<version>_<arch>.deb ./docker-compose-plugin_<version>_<arch>.deb
Start Docker and verify the installation:
sudo service docker start
sudo docker run hello-world
Post-Installation Steps
To allow non-privileged users to run Docker commands, add your user to the docker group:
sudo usermod -aG docker $USER