How to Install Docker on Ubuntu?

How to Install Docker on Ubuntu?

Docker has simplified SDLC by introducing a new way of deploying applications and their dependencies within a few minutes. We know that Docker creates isolated spaces called containers and encapsulates the application within them, which allows us to deal with microservices architecture too. Docker is available on most platforms including Ubuntu, a mostly used Linux distribution.
In this blog, we will discover how to Install Docker on Ubuntu.

Table of Contents

What is Docker?

What is Docker


Docker is an open-source containerization platform that simplifies the sharing, deployment, and maintenance of application code by allowing developers to convert the code into an image called a Docker image and then run these images within the isolated spaces created by Docker called containers. Since you are here to install Docker on Ubuntu, we assume you are already aware of the Docker tool, its features, functionalities, architecture, components, advantages, and other related terminologies.

Prerequisites for Installing Docker on Ubuntu

Installing Docker on Ubuntu is very simple and it can be installed on any of the versions available for Ubuntu. Let us see what prerequisites you need to meet:

Operating System Requirements that you need to meet:

Any of the below versions will work for you.

  • Ubuntu 24.10 (Oracular )
  • Ubuntu 24.04 (Noble LTS)
  • Ubuntu 22.04 (Jammy LTS)
  • Ubuntu20.04 ( Focal LTS)

It is compatible with architectures like x86_64/amd64, armhf, arm64, s390x, and ppc64le.

Uninstall any old Versions of Docker installed

Most of the Linux distributions including Ubuntu, by default, provide unofficial docker packages which can be unpacked by just running one or two commands on your system and you will be able to install and run docker within minutes. It might run in the same way as the official Docker runs. But, we always recommend you follow the official approach to installing Docker.

In such cases, existing packages of Docker might create a conflict for the new official package so you need to uninstall such packages first. A few of the unofficial packages available are docker.io, docker-compose, docker-compose-v2, docker-doc, and podman-docker.

To uninstall such packages, you can run the command like:

$for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

Installing Docker on Ubuntu

Docker Installation process on Ubuntu

Installing Docker on Ubuntu is a simple and easy process where you just need to run new commands in order. You can install Docker Engine directly using the APT repository or using the Docker Desktop. Just access the terminal or your environment and start running the below commands.

Lead the DevOps Industry with Confidence
Enroll in Our DevOps Course
quiz-icon

Method 1: Installing Docker Engine Using APT repository

1. We will update the current packages available in your machine and install additional required packages and a GPG key to ensure that we have downloaded the correct and official Docker package.

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

2. Now, we will add the 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 "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

3. Install the Latest Docker Package

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

4 Specific Docker Package:

If you are planning to install Docker on a specific package of Ubuntu, you need to list the the available versions in the repository and then install the desired version.

apt-cache madison docker-ce | awk '{ print $3 }'

As a response of the above command, you will be displayed a version available in your environment, you need to select and run it.

sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin

5. Verify Docker Installation: 

In order to check if you were successfully able to install Docker or not, you can try running hello-world image by running sudo docker run hello-world.

This will download a test image and run it in a container. If the container runs, it will print a confirmation message and exit.

Method 2: Install Docker Engine on Ubuntu using Docker Desktop

Docker Desktop is another way to install Docker Engine on Linux with Graphical User Interface. The process of configuring Docker remains the same.

  1. Setup a Docker package repository.
  2. You need to download the latest DEB package and then install it using the below commands:
sudo apt-get update
sudo apt-get install ./docker-desktop-amd64.deb

Once installed, you can try launching the application by simply double-clicking on it.

Executing the Docker Command Without Sudo

If you do not want to use the “sudo” keyword again and again with every Docker command, you need to create a user, add it to the Docker group, and restart the service.

sudo usermod -aG docker ubuntu
sudo service docker restart

Working with Docker Containers, Images, Dockerfile, and Commands

Once you have installed Docker successfully, you can start using Docker commands to achieve your tasks. Let’s run a few of the popular docker commands:

Docker Run Command

This command helps you run a test container
docker run hello-world

Pulling an Image from a Docker Registry

This command will help you to download a public image in your system.

docker pull mysql:5.5.45

Listing Images

It lists all Docker images present in your system.

docker images

Creating a Container using a specific image

docker run -it -d –name container_name image_name

Listing All Containers

This will help you to list all containers.

docker ps -a
Master Essential DevOps Concepts at No Cost
Take Advantage of Our Free DevOps Course
quiz-icon

Running container on specific port number

docker run -it -d –name container_name -p 81:80 image_name

Executing a Container

If you want to go inside the container to make any changes in the container environment, you can use the below command.

docker exec -it container_name bash

Committing Changes in a Container to a Docker Image

docker commit -m container_id container_id repository/new_image_name

Removing Images

docker rmi image_name

Stopping Docker Container

docker stop container_name

Removing Docker Container

docker rm container_name 

Creating Dockerfile

Create a file in your system with the name Dockerfile. If you are using the Ubuntu operating system, run:

nano Dockerfile 

Once the editor launches, write the below syntax to create a Dockerfile that will create an Apache Server image.

FROM ubuntu
RUN apt-get update
RUN apt-get install -y apache2
ENTRYPOINT apachectl -D FOREGROUND

Building a Dockerfile

The command will create an image for the Apache web server from the Dockerfile above.

docker build . -t new_image_name

Pushing Docker Images to a Docker Repository

Firstly, you need to log in to your Docker Hub account.

docker login

Enter your Docker Hub username and Password.

Once logged in, run the next command:

docker push repository/new_image_name

In order to learn more commands, you can follow the Docker commands guide.

Get 100% Hike!

Master Most in Demand Skills Now!

How To Install Docker on Ubuntu – FAQs

How to Install Docker on Windows?

Installing Docker on Windows is as simple as installing Docker on Ubuntu. We recommend you visit the correct Docker installation guide.

How Do I Know Docker is Installed on Ubuntu?

You can verify by pulling a docker test image or running the command docker –version.

How to Start Docker in Ubuntu Terminal?

To start Docker, use the command:

sudo systemctl start docker

What is Docker Used For?

Docker is used for automating the deployment and management of applications in lightweight, portable, isolated space containers.

How to Stop Docker?

Run sudo systemctl stop docker command to stop Docker.

Break it down step by step with this informative video.

Conclusion

This comprehensive guide covers the essential aspects of installing Docker on Ubuntu. Docker is a powerful containerization platform that offers numerous benefits for developers and system administrators, including improved security, portability, resource efficiency, and reproducibility. Understanding the concept of Docker and verifying system requirements is crucial before starting the installation process. Following the step-by-step instructions in this guide, you can successfully install Docker on your Ubuntu system and leverage its capabilities. If you are looking to learn tools like Docker, enroll in our top DevOps course.

Our Devops Courses Duration and Fees

Program Name
Start Date
Fees
Cohort starts on 4th Feb 2025
₹22,743
Cohort starts on 28th Jan 2025
₹22,743
Cohort starts on 14th Jan 2025
₹22,743

About the Author

Senior Cloud Computing Associate

Rupinder is a distinguished Cloud Computing & DevOps associate with architect-level AWS, Azure, and GCP certifications. He has extensive experience in Cloud Architecture, Deployment and optimization, Cloud Security, and more. He advocates for knowledge sharing and in his free time trains and mentors working professionals who are interested in the Cloud & DevOps domain.

EPGC Cloud