Install Docker on Ubuntu 24.04

  1. Uninstall Conflicting Packages

Remove any existing Docker packages to avoid conflicts:

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

  1. Update Package Index

Ensure your package index is up-to-date:

sudo apt-get update

  1. Install Prerequisite Packages
sudo apt-get install ca-certificates curl

  1. Add Docker’s Official GPG Key

Add Docker’s GPG key to verify package authenticity:

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

  1. Set Up the Docker Repository

Add Docker’s official repository to your system:

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
sudo apt-get update

  1. Install the Docker packages

Install Docker Engine, CLI, and containerd:

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

  1. Verify Docker Installation

Run a test container to confirm Docker is installed correctly:

sudo docker run hello-world

If successful, you’ll see a message confirming Docker’s proper installation.


  1. Enable Docker for Non-Root Users

By default, Docker commands require sudo. To allow your user to run Docker without sudo, add your user to the docker group:

sudo usermod -aG docker $USER

Note: This change only takes effect after you log out and log back in, or you can reboot the system:

sudo reboot

After logging back in, test Docker again without sudo:

docker run hello-world

If successful, you’ll see the same confirmation message, no sudo required.

Security Warning: Adding a user to the docker group effectively grants root-level access. Be cautious on multi-user systems.

Leave a Comment

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

Scroll to Top