To install Docker on Ubuntu, follow these steps:
1. Uninstall Old Versions (Optional)
If you have older versions of Docker installed, remove them:
sudo apt-get remove docker docker-engine docker.io containerd runc
2. Update Package Information
Update your existing package list:
sudo apt-get update
3. Install Required Packages
Install necessary prerequisites for Docker:
sudo apt-get install -y ca-certificates curl gnupg
4. Add Docker’s Official GPG Key
Add Docker's official GPG key for verifying the repository:
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
5. Set Up the Docker Repository
Add the Docker repository to your sources list:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
6. Update the Package Index
Update the package index to include the Docker repository:
sudo apt-get update
7. Install Docker Engine
Install Docker Engine, containerd, and Docker CLI:
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
8. Verify Docker Installation
Check if Docker is installed and running:
sudo docker --version
sudo docker run hello-world
9. Optional: Run Docker Without sudo
To allow your user to run Docker without sudo
:
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
Test again by running:
docker run hello-world
This will install Docker and set it up properly on your Ubuntu system.
Top comments (0)