Docker is a free, open-source tool for application containerization. Containers are isolated environments similar to virtual machines (VMs), but they are more lightweight and portable across platforms, requiring fewer system resources. Docker uses OS-level virtualization, leveraging features built into the Linux kernel.
This guide walks through installing Docker on Ubuntu 22.04 but also applies to other Ubuntu versions. Additionally, we’ll download Docker Compose, a tool essential for managing multiple containers efficiently.
For this guide, we will use a Hostman cloud server.
According to Docker's documentation, the following 64-bit Ubuntu versions are supported:
Ubuntu Oracular 24.10
Ubuntu Noble 24.04 (LTS)
Ubuntu Jammy 22.04 (LTS)
Ubuntu Focal 20.04 (LTS)
Docker works on most popular architectures. The resource requirements for your device will depend on your intended use and how comfortably you want to work with Docker. The scale of applications you plan to deploy in containers will largely dictate the system needs. Some sources recommend a minimum of 2 GB of RAM.
Additionally, a stable internet connection is required.
Installing Docker on Ubuntu 22.04 involves executing a series of terminal commands. Below is a step-by-step guide with explanations. The steps are also applicable to server versions of Ubuntu.
1. Update Package Indexes
The default repository may not always contain the latest software releases. Therefore, we will download Docker from its official repository to ensure the latest version. First, update the package indexes:
sudo apt update
2. Install Additional Packages
To install Docker, you’ll need to download four additional packages:
curl
: Required for interacting with web resources.software-properties-common
: Enables software management via scripts.ca-certificates
: Contains information about certification authorities.apt-transport-https
: Necessary for data transfer over the HTTPS protocol.Download these packages with the following command:
sudo apt install curl software-properties-common ca-certificates apt-transport-https -y
The -y
flag automatically answers "Yes" to all terminal prompts.
3. Import the GPG Key
The GPG key is required to verify software signatures. It is needed to add Docker's repository to the local list. Import the GPG key with the following command:
wget -O- https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor | sudo tee /etc/apt/keyrings/docker.gpg > /dev/null
During the import process, the terminal may display a warning before confirming the successful execution of the command.
4. Add Docker Repository
Add the repository for your version of Ubuntu, named "Jammy." For other versions, use their respective code names listed in the "System Requirements" section. Run the following command:
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
During execution, the terminal will prompt you to confirm the operation. Press Enter.
5. Update Package Indexes Again
After making these changes, update the package indexes once more using the familiar command:
sudo apt update
6. Verify the Repository
Ensure that the installation will proceed from the correct repository by running the following command:
apt-cache policy docker-ce
Output example:
The output may vary depending on the latest Docker releases. The key point is to confirm that the installation will be performed from Docker's official repository.
7. Installing Docker
After configuring the repositories, proceed with the Docker installation:
sudo apt install docker-ce -y
The installation process will begin immediately. To confirm a successful installation, check Docker's status in the system:
sudo systemctl status docker
Output example:
The output should indicate that the Docker service is active and running.
Docker Compose is a Docker tool designed for managing multiple containers. It is commonly used in projects where many containers must work together as a unified system. Managing this process manually can be challenging. Instead, you describe the entire configuration in a single YAML file containing the settings and configurations for all containers and their applications.
There are several ways to install Docker Compose. If you need the latest version, make sure to use manual installation and installation via the Git version control system.
If having the latest version is not critical for you, Docker Compose can be installed directly from the Ubuntu repository. Run the following command:
sudo apt-get install docker-compose
First, install Git:
sudo apt-get install git
Verify the installation by checking the Git version:
git --version
The output should show the Git version.
Next, clone the Docker Compose repository. Navigate to the Docker Compose GitHub page and copy the repository URL.
Run the following command to clone the repository:
git clone https://github.com/docker/compose.git
The cloning process will begin, and the repository will be downloaded from GitHub.
Go to the Docker Compose GitHub repository and locate the latest release version under the Latest tag.
At the time of writing, the Latest version of Docker Compose is v2.31.0. Let's download it:
sudo curl -L "https://github.com/docker/compose/releases/download/v2.31.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
In this command, the parameters $(uname -s)
and $(uname -m)
automatically account for the system characteristics and architecture. After the download finishes, change the file's permissions:
sudo chmod +x /usr/local/bin/docker-compose
In this guide, we covered the installation of Docker on Ubuntu 22.04, along with several ways to install Docker Compose. You can order a cloud server at Hostman for your experiments and practice.