How to Install and Setup Docker on Ubuntu 24.04

Why Install Docker on Ubuntu?

Docker is a powerful containerisation platform that allows developers to package applications and their dependencies into isolated, lightweight environments called containers. Running Docker on Ubuntu 24.04 (Noble Numbat) is highly recommended, as Ubuntu is one of the most stable and widely supported Linux distributions for server and development environments.

Step 1: Update Your System Packages

Before installing new software, you should always ensure your local package index is up to date and your system packages are upgraded to their latest versions.

  1. Open your terminal application.
  2. Run the following command to update your package index:
    sudo apt update
  3. Upgrade your existing packages by running:
    sudo apt upgrade -y

Step 2: Install Required Dependencies

Docker requires a few prerequisite packages to allow the apt package manager to use repositories over HTTPS.

Run the following command in your terminal:

sudo apt install ca-certificates curl gnupg -y

Step 3: Add Docker’s Official GPG Key

To ensure you are downloading the authentic software directly from Docker, you must add Docker’s official GPG key to your system keyring.

  1. Create the directory for the keyring:
    sudo install -m 0755 -d /etc/apt/keyrings
  2. Download the key and save it to the directory:
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo tee /etc/apt/keyrings/docker.asc > /dev/null
  3. Ensure the key has the correct permissions:
    sudo chmod a+r /etc/apt/keyrings/docker.asc

Step 4: Add the Docker Repository

Next, you need to add the official Docker repository to your Ubuntu system sources so that apt knows where to download the Docker engine.

Run this command to add the stable repository:

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

Update your package index once more to recognize the new repository:

sudo apt update

Step 5: Install Docker Engine

You are now ready to install the Docker Engine, the Command Line Interface (CLI), and the Docker Compose plugin.

Run the installation command:

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

Step 6: Verify the Installation

To confirm that Docker has been successfully installed and is running properly, you can run the built-in “hello-world” container.

sudo docker run hello-world

If the installation was successful, Docker will download a test image and print a “Hello from Docker!” message to your terminal, confirming that the daemon is active.

Step 7: Run Docker Without Sudo (Optional but Recommended)

By default, running Docker commands requires root privileges (using sudo). If you want to run Docker as a standard user, you must add your user account to the docker group.

  1. Add your user to the docker group:
    sudo usermod -aG docker $USER
  2. Apply the new group membership by logging out and back in, or by running this command to activate the changes immediately:
    newgrp docker

You can now run Docker commands without prefixing them with sudo.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.