How To Install Docker on Ubuntu 22.04 LTS
In this tutorial, we will show you how to install Docker on Ubuntu 22.04 LTS. Docker containers have revolutionized the way applications are developed, packaged, and deployed. They provide a consistent, portable, and efficient environment for running software, making it easier to manage dependencies, ensure consistency across different systems, and scale applications. By leveraging Docker containers, developers and organizations can streamline their development and deployment processes, reduce conflicts, and improve overall efficiency.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the Docker containers on Ubuntu 22.04 (Jammy Jellyfish). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.
Prerequisites
- A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Docker on Ubuntu 22.04 LTS Jammy Jellyfish
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade sudo apt install ca-certificates curl gnupg lsb-release apt-transport-https
Step 2. Installing Docker on Ubuntu 22.04.
By default, Docker is not available on Ubuntu 22.04 base repository. Now run the following command below to add the Docker repository to the system:
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
Next, import the GPG key to your system:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
After the repository is enabled, now install the latest version of the Docker package using the below command:
sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
You can verify that Docker is installed and about the current version:
docker -v
Once successfully installed, enable Docker (to start automatically upon system boot), start, and verify the status using the commands below:
sudo systemctl enable docker sudo systemctl start docker sudo systemctl status docker
In addition, consider adding the currently logged-in user to the docker group. This allows you to run docker without invoking sudo
:
sudo usermod -aG docker my_user newgrp docker
Step 3. Test Docker.
Once successfully installed, now we will pull a ‘hello-world
’ image from Docker Hub. From the image, a container will be created that displays a ‘Hello world’ message on the terminal along with the steps of what just happened after the command was executed:
sudo docker run hello-world
Output:
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
Now you can search for available images on Docker Hub, for example, run the following command to search Ubuntu Linux images:
docker search ubuntu
When you choose the image that you want to use, you can run the following command to download the image:
docker pull ubuntu
To see the images you have downloaded, run the following command:
docker images
Congratulations! You have successfully installed Docker. Thanks for using this tutorial for installing the Docker containers on Ubuntu 22.04 LTS Jammy Jellyfish system. For additional help or useful information, we recommend you check the official Docker website.