Docker 101: How to Install Docker on Ubuntu Server 22.04

Compared to other solutions, Docker is more user-friendly, offers many graphical applications (so you don’t always have to work from the command line), and is supported on Linux, macOS, and Windows.

Also: Docker 101: why you should use containers

I have deployed hundreds of applications and services with this tool and found it to be an invaluable part of my daily workflow. In many cases, deploying the containerized application via Docker is much faster and more reliable than manually deploying the same application/service.

I’ll show you how to do just that. I’ll be demoing on Ubuntu Server 22.04, which means the process should work on any Ubuntu (or Debian) based distro. As for distributions based on Red Hat Enterprise Linux (such as Rocky Linux, AlmaLinux, CentOS Stream and Feodra Linux), these platforms migrated to Podman as the default container runtime, and the installation of Docker is not only very difficult, it tends to break more things than it fixes.

So if RHEL-based distros are your jam, leave it alone and stick with Podman. However, if you’re looking at Ubuntu-based distros, Docker isn’t just available, it’s really easy to install. To this end, I will demonstrate on Ubuntu Server 22.04. To follow, you will need an Ubuntu-based distribution and a user with sudo privileges.

Ready? Let’s go to the installation.

Installation on Ubuntu

1. Add the necessary repository

The first thing you need to do is login to your Ubuntu instance and add the necessary repository (because the version of Docker found in the standard repository is not the latest community edition we want). Once connected, add the official Docker GPG key with the command:

curl -fsSL | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Next, add the official Docker repository:

echo “deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] $(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

2. Install necessary dependencies

We will then install the required dependencies with the command:

sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y

3. Install Docker

Finally, update apt and install Docker with the following commands:

sudo apt-get update sudo apt-get install docker-ce docker-ce-cli -y

4. Add your user to the Docker group

In order to be able to use Docker without having to invoke it with sudo (which can lead to security issues), you need to add your user to the docker group with:

sudo usermod -aG $USER docker

Log out and log back in for the changes to take effect.

Docker is now ready to use on your Ubuntu machine.

Test the installation

Once Docker is installed, you can verify the installation by running the command:

In the output, you should see something like this:

Server: Docker Engine – Community Engine: Version: 20.10.14

Let’s make sure your user can run a Docker command by dropping the hello-world image with:

If the image is successfully pulled, congratulations, Docker is installed and ready to go. Next time you will learn how to deploy your first container with Docker.

Source link

Steven L. Nielsen