To install Docker on Ubuntu, follow these steps:
Step 1: Update the System
Run the following commands to update your system’s package index and install required prerequisites:
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg lsb-release
Step 2: Add Docker’s Official GPG Key
Add Docker’s GPG key to ensure the software is authentic:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Step 3: Add Docker’s Official Repository
Add Docker’s repository to your package manager:
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
Step 4: Install Docker Engine
Update your package index again and install Docker Engine, CLI, and containerd:
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 5: Verify the Installation
Run the following command to ensure Docker is installed correctly:
sudo docker --version
You should see the Docker version output.
Step 6: (Optional) Run Docker as a Non-root User
To run Docker without using sudo
, add your user to the docker
group:
- Add the current user to the
docker
group:
sudo usermod -aG docker $USER
- Log out and back in, or run:
newgrp docker
- Verify:
docker run hello-world
Step 7: Test Docker
Test Docker by running the following command:
docker run hello-world
This will download a test image and run it in a container.
If you encounter issues during installation, let me know!