Docker is a popular containerization platform that allows you to package, deploy, and run applications in a standardized environment. With Docker, you can manage your applications as lightweight containers that are portable and consistent across different environments. In this guide, we’ll walk you through the steps to install Docker on Ubuntu 24.04 (LTS).
Prerequisites
Before you begin, ensure that you have the following:
- A 64-bit version of Ubuntu 24.04 (LTS)
- A user account with
sudo
privileges
Docker supports multiple architectures, including x86_64
, armhf
, arm64
, s390x
, and ppc64le
.
Step 1: Update Your System
Before installing any new software, it’s a good practice to update your system’s package list. Open a terminal and run the following command:
sudo apt-get update
This command updates the list of available packages and their versions.
Step 2: Install Required Packages
To set up Docker on your system, you need to install a few prerequisite packages. These packages help in adding the Docker repository and managing the keys securely:
sudo apt-get install ca-certificates curl gnupg
This command installs ca-certificates
, curl
, and gnupg
, which are required for Docker installation.
Step 3: Add Docker’s Official GPG Key
Next, you need to add Docker’s official GPG key to your system. This key ensures that the software you’re about to install is authentic and hasn’t been tampered with:
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
This will download the GPG key and place it in the appropriate directory on your system.
Step 4: Set Up Docker Repository
With the GPG key added, you can now add the Docker repository to your system’s list of repositories:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
This command sets up the repository from which Docker can be installed and updated.
Step 5: Install Docker Engine
With the repository set up, you can now install Docker Engine and its associated components:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
This installs the latest version of Docker, including the Docker Engine, Docker CLI, and additional plugins.
Step 6: Verify Docker Installation
After the installation is complete, you can verify that Docker was installed correctly by running the hello-world
image:
sudo docker run hello-world
If everything is working properly, you should see a message that says “Hello from Docker!” This confirms that Docker is installed and running.
Step 7: Post-Installation Steps (Optional)
7.1 Run Docker Commands Without Sudo
By default, Docker commands require sudo
privileges. If you want to allow your user to run Docker commands without sudo
, follow these steps:
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
#restart your pc
After running these commands, log out and log back in to apply the changes.
7.2 Enable Docker to Start on Boot
To ensure that Docker starts automatically when your system boots, run the following command:
sudo systemctl enable docker
This will configure Docker to start automatically each time your system starts up.
Step 8: Upgrading Docker Engine
To upgrade Docker Engine to a newer version, simply update your package index and install the latest version:
sudo apt-get update
sudo apt-get upgrade docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
This will upgrade Docker to the latest version available in the repository.
Uninstalling Docker Engine
If you ever need to uninstall Docker, you can do so with the following command:
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
If you want to remove all Docker data, including images, containers, and volumes, you can do so by running:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
Conclusion
Congratulations! You’ve successfully installed Docker on your Ubuntu 24.04 (LTS) system. Docker is now ready to help you create, deploy, and manage containers efficiently. Whether you are developing locally or deploying in production, Docker provides a robust and flexible platform for all your containerization needs.
If you encounter any issues or need further information, the official Docker documentation is a great resource.
Additionally, feel free to leave comments or questions below for further clarification!