Skip to main content

How To Install Docker On Ubuntu 24

· 7 min read
Sivabharathy

Docker is a powerful platform that allows you to easily develop, package, and deploy applications in containers. Containers are lightweight, portable, and provide a consistent environment for running applications. Installing Docker on Ubuntu 24.04 is a straightforward process, but it requires a few steps to set up correctly.

In this article, we will walk you through the complete process of installing Docker on Ubuntu 24.04. We will also provide troubleshooting tips and post-installation instructions.

Prerequisites

Before starting the installation, ensure that you have the following:

  • A fresh installation of Ubuntu 24.04 (or any Ubuntu-based system).
  • Access to a terminal or command-line interface.
  • Root or sudo privileges on the system.

Step 1: Update the System

It’s always a good idea to update your system before installing any software. Run the following commands to ensure your system is up-to-date:

sudo apt update
sudo apt upgrade -y

These commands will update the package list and install any available updates. This will ensure that you don’t run into issues due to outdated packages.


Step 2: Install Required Dependencies

Docker requires some dependencies to be installed before proceeding with the actual installation. These dependencies help manage the Docker repository and ensure a smooth installation process.

Run the following command to install these dependencies:

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
  • apt-transport-https: Ensures that apt can access repositories over HTTPS.
  • ca-certificates: Provides certificates that ensure secure communication with Docker’s servers.
  • curl: A tool to download files from the web. We’ll use it to fetch Docker’s official GPG key.
  • software-properties-common: A utility for managing repository sources.

Step 3: Add Docker’s Official GPG Key

To ensure that the software you are installing is authentic, Docker provides a GPG key that verifies the integrity of its packages. Use curl to fetch Docker’s GPG key and add it to your system’s keyring:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

This command does the following:

  • Downloads the GPG key from Docker’s official website.
  • Saves it to the /usr/share/keyrings directory on your system.

Step 4: Add Docker’s Official Repository

Now that you have Docker’s GPG key, you need to add Docker’s official APT repository to your system’s list of sources. This will allow you to install Docker from the official Docker repository.

Run the following command to add the Docker repository:

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Here’s a breakdown of this command:

  • deb: Adds the repository to the APT sources list.
  • [arch=amd64]: Specifies that we’re installing the AMD64 version (for 64-bit systems).
  • signed-by=/usr/share/keyrings/docker-archive-keyring.gpg: Points to the GPG key that verifies the Docker packages.
  • https://download.docker.com/linux/ubuntu: The URL of Docker’s repository.
  • $(lsb_release -cs): Automatically fetches the correct codename for your Ubuntu version (e.g., focal for Ubuntu 20.04, jammy for Ubuntu 22.04, etc.).
  • stable: Specifies that you want to use the stable release of Docker.

Step 5: Update the Package Database

Now that Docker’s official repository has been added, you need to update your package list. This will ensure that your system is aware of the latest Docker packages available for installation.

sudo apt update

This command refreshes the package index with the latest software available from all configured repositories.


Step 6: Install Docker Engine

With Docker’s repository now available, you can proceed to install Docker on your system. Run the following command:

sudo apt install -y docker-ce docker-ce-cli containerd.io

Here’s what each package does:

  • docker-ce: The Docker Engine (Community Edition), the core Docker package that provides the runtime environment.
  • docker-ce-cli: The Docker command-line interface that allows you to interact with Docker.
  • containerd.io: A core container runtime used by Docker for managing containers.

This installation process may take a few minutes to complete, depending on your internet speed and system performance.


Step 7: Start and Enable Docker Service

After Docker is installed, you need to start the Docker service and ensure that it starts automatically on system boot. To start Docker, run the following command:

sudo systemctl start docker

To ensure that Docker starts automatically on boot, use the following command:

sudo systemctl enable docker

You can verify that Docker is running by checking its status:

sudo systemctl status docker

You should see an output that indicates Docker is active and running:

● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since ...

Step 8: Verify Docker Installation

To ensure that Docker was installed and is running correctly, you can check the version of Docker:

docker --version

You should see an output similar to this, depending on the version of Docker you installed:

Docker version 24.0.0, build 1234567

Next, you can run the hello-world container to confirm that Docker is functioning properly:

docker run hello-world

This will download the hello-world image from Docker Hub and run it in a container. If Docker is correctly installed, you will see the following message:

Hello from Docker!
This message shows that your installation appears to be working correctly.

Step 9: (Optional) Add User to Docker Group

By default, Docker commands require sudo privileges. If you want to run Docker commands without using sudo, you can add your user to the Docker group.

To do this, run:

sudo usermod -aG docker $USER

After running this command, log out and log back in, or restart your system to apply the changes. Once you’ve done this, you should be able to run Docker commands without sudo.


Step 10: Test Docker with a Container

To further test that Docker is installed correctly, you can run another test container. For example, to run a simple Nginx web server, run the following command:

docker run -d -p 80:80 nginx

This will:

  • Download the Nginx image from Docker Hub if you don’t already have it.
  • Run the Nginx container in the background (-d flag).
  • Map port 80 on your machine to port 80 on the container (-p 80:80 flag).

You can then visit http://localhost in your browser, and you should see the Nginx welcome page, indicating that your Docker container is running.


Uninstalling Docker (Optional)

If you ever need to uninstall Docker, you can follow these steps:

  1. Remove Docker Packages:
sudo apt remove --purge docker-ce docker-ce-cli containerd.io
  1. Remove Docker Images, Containers, Volumes, and Networks:

To remove all Docker data (images, containers, volumes, networks), run:

sudo rm -rf /var/lib/docker
  1. Remove Docker Repository (Optional):

If you no longer want the Docker repository on your system, remove the Docker list file:

sudo rm /etc/apt/sources.list.d/docker.list

Conclusion

You have now successfully installed Docker on Ubuntu 24.04! Docker is an essential tool for developers and system administrators who need to create, test, and deploy applications inside containers. With Docker installed, you can begin creating and managing containers for your applications.

If you encounter any issues during installation, feel free to check Docker's official documentation for further troubleshooting steps.