Docker is a software platform that packages the application and all its dependencies in containers – small, portable, and lightweight execution environments that share the operating system’s kernel but otherwise operate in isolation.
This guide will walk you effortlessly through the steps required to install Docker on Ubuntu 22.04 LTS to get started with containerization and make the most of this powerful tool.
However, if you came across this guide looking for one for Ubuntu 24.04 LTS (Noble Numbat), you can find it here.
Installing Docker on Ubuntu 22.04
There are several ways you can install Docker on your Ubuntu 22.04 system. For example, it is available in the official Ubuntu repositories, where it can be easily installed with a single APT command. However, one disadvantage to this approach is that the version available is not always the most recent.
For this reason, this guide will show you how to install Docker on Ubuntu 22.04 from the official Docker repository, where you always get the latest up-to-date version and will automatically receive all future software updates as they become available. So, let’s get started.
Step 1: Install Prerequisites
First, run the two commands below to update the package index and install the prerequisite necessary to add and use a new HTTPS repository.
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release
Code language: Bash (bash)
Step 2: Add Dockerโs Official GPG Key
Next, import the Docker GPG repository key to your Ubuntu system. This security feature ensures that the software you’re installing is authentic.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Code language: Bash (bash)
Notice that the command produces no output.
Step 3: Add Docker Repo to Ubuntu 22.04
After importing the GPG keys, weโll add the official Docker repository to our Ubuntu 22.04 system. This implies that the update package will be made available with the rest of your systemโs regular updates if a new version is released.
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Code language: Bash (bash)
As with the previous command, its execution produces no output.
Next, refresh the package list.
sudo apt update
Code language: Bash (bash)
As you can see, our new Docker repository is now available and ready to be used.
Step 4: Install Docker on Ubuntu 22.04
To install the latest up-to-date Docker release on Ubuntu, run the below command.
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Code language: Bash (bash)
This installs the following Docker components:
- docker-ce: The Docker engine itself.
- docker-ce-cli: A command line tool that lets you talk to the Docker daemon.
- containerd.io: A container runtime that manages the container’s lifecycle.
- docker-buildx-plugin: A CLI plugin that extends the Docker build with many new features.
- docker-compose-plugin: A configuration management plugin to orchestrate the creation and management of Docker containers through compose files.
That’s all! Docker should now be installed; the service started and enabled to start automatically on boot.
In addition, you can check the Docker service status using the following:
sudo systemctl is-active docker
Code language: Bash (bash)
Step 5: Verify the Docker Installation
Now let’s check if everything with our new Docker installation works properly. For this purpose, we will run a simple application called “hello-world.”
sudo docker run hello-world
Code language: Bash (bash)
Congratulations! As we can see, everything works as expected!
Enabling Non-root Users to Run Docker Commands
So far, we have successfully installed Docker on your Ubuntu 22.04 system.
However, only root and users with sudo privileges can execute Docker commands by default. In other words, if you attempt to run the docker
command without prefixing it with sudo
, youโll get an error message like this:
So, to run Docker commands as a non-root user, you must add your user to the docker group. To do that, type in the following:
sudo usermod -aG docker ${USER}
Code language: Bash (bash)
In the above command, ${USER}
is an environment variable that holds your username. To apply for the new group membership, reboot your Ubuntu system. You will then be able to execute docker
commands without having to prefix them with sudo
.
Conclusion
Docker is a powerful tool that can significantly enhance your ability to manage and deploy applications lightweight and efficiently. By following the steps outlined in this article, you should have a working Docker installation on your Ubuntu 22.04 system.
Furthermore, Docker Desktop is your solution if you want to make things even easier and manage your containers through an intuitive and easy-to-use GUI app. Here’s our tutorial on how to install it on Ubuntu.
So, what are you waiting for? Start experimenting with Docker on your Ubuntu system today and see how it can revolutionize how you build and deploy applications.
To learn more about Docker, check out the official Docker documentation.