DEV Community

Cover image for Install Docker on Ubuntu
Md Abu Musa
Md Abu Musa

Posted on

1

Install Docker on Ubuntu

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
Enter fullscreen mode Exit fullscreen mode

2. Update Package Information

Update your existing package list:

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

3. Install Required Packages

Install necessary prerequisites for Docker:

sudo apt-get install -y ca-certificates curl gnupg
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

6. Update the Package Index

Update the package index to include the Docker repository:

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

8. Verify Docker Installation

Check if Docker is installed and running:

sudo docker --version
sudo docker run hello-world
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Test again by running:

docker run hello-world
Enter fullscreen mode Exit fullscreen mode

This will install Docker and set it up properly on your Ubuntu system.

Billboard image

Monitor more than uptime.

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay