DEV Community

Cover image for Install Docker on Ubuntu
coder7475
coder7475

Posted on

1

Install Docker on Ubuntu

Before installing Docker Engine on a new Ubuntu host machine, you need to set up the Docker apt repository. Once the repository is configured, you can install and update Docker directly from it.


1. Set up Docker's apt repository

Follow these steps to configure the repository:

# Update package index and install prerequisites:
sudo apt-get update
sudo apt-get install -y ca-certificates curl

# Create a directory for Docker's GPG key:
sudo install -m 0755 -d /etc/apt/keyrings

# Download Docker's official GPG key:
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

# Add Docker's repository to Apt sources:
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

# Update the package index again:
sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

2. Install Docker packages

Install the latest version of Docker Engine and its components:

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Enter fullscreen mode Exit fullscreen mode

3. Check Docker and containerd status

Verify that Docker and containerd services are running:

sudo systemctl status containerd
sudo systemctl status docker
Enter fullscreen mode Exit fullscreen mode

If either service is inactive, start them using:

sudo systemctl start containerd
sudo systemctl start docker
Enter fullscreen mode Exit fullscreen mode

4. Verify the installation

Run the hello-world image to confirm Docker is working correctly:

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

This command downloads a test image, runs it in a container, and prints a confirmation message.


5. Run Docker without sudo

To avoid using sudo with every Docker command, add your user to the Docker group:

sudo usermod -aG docker $USER
newgrp docker
Enter fullscreen mode Exit fullscreen mode

6. Final verification

Run the hello-world image again, this time without sudo:

docker run hello-world
Enter fullscreen mode Exit fullscreen mode

If successful, you have installed and configured Docker Engine on your Ubuntu machine.


References

  1. Docker Documentation
  2. Docker Installation Challenge

Warp.dev image

The best coding agent. Backed by benchmarks.

Warp outperforms every other coding agent on the market, and gives you full control over which model you use. Get started now for free, or upgrade and unlock 2.5x AI credits on Warp's paid plans.

Download Warp

Top comments (0)

Runner H image

Automate Your Workflow in Slack, Gmail, Notion & more

Runner H connects to your favorite tools and handles repetitive tasks for you. Save hours daily. Try it free while it’s in beta.

Try for Free

👋 Kindness is contagious

Explore this insightful piece, celebrated by the caring DEV Community. Programmers from all walks of life are invited to contribute and expand our shared wisdom.

A simple "thank you" can make someone’s day—leave your kudos in the comments below!

On DEV, spreading knowledge paves the way and fortifies our camaraderie. Found this helpful? A brief note of appreciation to the author truly matters.

Let’s Go!