How to Install Docker on Ubuntu 24.04
What is Docker?
Docker is an open-source platform that allows packaging, distributing, and running applications efficiently in any environment: Linux, Windows, Mac, or the cloud.
Written in the Go programming language, Docker uses operating system-level virtualization to run applications in isolated environments called containers. These include everything needed for the application to function correctly: source code, binaries, dependencies, and libraries, ensuring portability and stability.
1. Update the System and Install Dependencies
First, update the system packages:
sudo apt updateCopied!
Then, install the necessary packages for the installation:
sudo apt install curl apt-transport-https ca-certificates software-properties-commonCopied!
2. Install Docker
Option 1: Install Docker from Ubuntu Repositories
You can install Docker directly from the default repositories:
sudo apt install docker.io -yCopied!
However, this version may not be the latest. To install the latest version from Docker’s official repository, follow these steps:
Option 2: Install the Latest Version from the Official Repository
1. Download Docker's GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpgCopied!
2. Add Docker's repository to the APT sources:
echo "deb [arch=$(dpkg --print-architecture) 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/nullCopied!
3. Update the package index:
sudo apt updateCopied!
4. Install Docker Community Edition (CE):
sudo apt install docker-ce -yCopied!
Docker will start automatically after installation. You can check its status with:
sudo systemctl status dockerCopied!
3. Add User to the Docker Group
By default, Docker requires root or sudo permissions to run. To run Docker without sudo, add your user to the docker group:
sudo usermod -aG docker $USERCopied!
Apply the changes without logging out:
su - ${USER}Copied!
Check that the user belongs to the docker group:
groupsCopied!
Expected output:
sudo docker
Now you can run Docker commands without sudo. For example, check the installed version:
docker versionCopied!
4. Test the Docker Installation
To check that Docker is working correctly, run the following command:
docker run hello-worldCopied!
Expected output:
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ... (output) Hello from Docker! This message shows that your installation appears to be working correctly.
What Happens in the Background?
- The Docker client searches for the hello-world image on the local system.
- If not found, it connects to Docker Hub and downloads the image.
- Docker creates a new container based on that image.
- The container runs and displays a confirmation message in the terminal.
With this, you have successfully installed and tested Docker on Ubuntu 24.04.
Conclusion
Docker allows you to package, distribute, and run applications efficiently in containers. With this installation, you can start exploring its ecosystem, from creating containers to managing more complex services with Docker Compose.
Next, we can explore more essential Docker commands or how to deploy real applications in containers.