Skip to content

Installing Docker on Ubuntu 22.04

This guide will walk you through the steps to install Docker on an Ubuntu 22.04 server, including setting up the firewall and OpenSSL.

Step 1: Update and Upgrade the System

First, update and upgrade your system packages to ensure you have the latest versions.

bash
sudo apt update && sudo apt upgrade -y

Step 2: Install Required Packages

Install the necessary packages for Docker and OpenSSL.

bash
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
sudo apt install openssl -y

Step 3: Add Docker’s Official GPG Key

Add Docker's official GPG key to your system.

bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Step 4: Set Up the Docker Repository

Add the Docker repository to APT sources.

bash
echo "deb [arch=amd64 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/null

Step 5: Install Docker

Update the package database with the Docker packages from the newly added repo and install Docker.

bash
sudo apt update
sudo apt install docker-ce -y

Step 6: Verify Docker Installation

Check the Docker version to verify the installation.

bash
docker --version

Step 7: Start and Enable Docker

bash
sudo systemctl status docker

Step 7: Manage Docker as a Non-root User

Add your user to the docker group to manage Docker as a non-root user.

bash
sudo usermod -aG docker ${USER}

Log out and log back in so that the group membership is re-evaluated.

Step 8: Set Up the Firewall

Install ufw (Uncomplicated Firewall) and allow necessary ports.

bash
sudo apt install ufw -y
sudo ufw allow OpenSSH
sudo ufw enable

To allow Docker to manage its own firewall rules, disable ufw's interaction with Docker.

bash
sudo nano /etc/ufw/ufw.conf

Set MANAGE_BUILTINS=no in the configuration file.

Step 9: Install OpenSSL

OpenSSL should already be installed from Step 2, but you can verify it with:

bash
openssl version

Conclusion

You have successfully installed Docker on your Ubuntu 22.04 server, set up the firewall, and installed OpenSSL. You can now start using Docker to manage your containers.