How to Install Docker on Ubuntu 22.04: A Complete Guide
Want to simplify application deployment? This guide walks you through a complete Docker installation on Ubuntu 22.04, covering everything from setup to running your first container. You'll learn how to install using the official Docker repository and manage Docker images. Let’s dive in.
Why Use Docker on Ubuntu? Effortless Application Management
Docker revolutionizes application management by using containers. It offers:
- Portability: Run your applications consistently across different environments.
- Resource Efficiency: Containers share the host OS kernel, using fewer resources than virtual machines.
- Isolation: Applications run in isolated environments, preventing conflicts.
This tutorial focuses on installing Docker CE on Ubuntu 22.04, empowering you to leverage these benefits.
Prerequisites for Installing Docker on Ubuntu 22.04
Before you install Docker, you’ll need:
- An Ubuntu 22.04 server with a
sudo
non-root user and firewall (follow the initial server setup guide). - A Docker Hub account (optional, for creating and pushing your own images).
Step 1: Installing Docker from the Official Repository
The Ubuntu repository might not have the latest Docker version. Let's install from the official Docker repository.
-
Update Packages: Start by updating your package list:
sudo apt update
-
Install Prerequisite Packages:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
These packages allow
apt
to use packages over HTTPS. -
Add Docker's GPG Key: To ensure valid downloads, add the GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
-
Add the Docker Repository:
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 > /dev/null
-
Update Packages (Again): Refresh your package list to recognize the new repository:
sudo apt update
-
Verify Installation Source: Confirm you're installing from the Docker repository:
apt-cache policy docker-ce
The output should show the candidate for installation from the Docker repository for Ubuntu 22.04 (
jammy
). -
Install Docker: Finally, install Docker:
sudo apt install docker-ce
With these steps completed, Docker CE is installed on your Ubuntu 22.04 system, the daemon is started, and it's set to start on boot.
Step 2: Verify Docker is Running
Confirm Docker is running correctly:
sudo systemctl status docker
The output should indicate that the docker.service
is active and running.
Step 3: Execute Docker Commands Without Sudo (Optional)
Running docker
commands typically requires sudo
. To avoid this, add your user to the docker
group:
sudo usermod -aG docker ${USER}
Log out and back in, or run su - ${USER}
to apply the changes. Verify your group membership with groups
.
Step 4: Using Docker Commands: A Quick Start
The basic syntax for docker
commands is:
docker [option] [command] [arguments]
See available commands:
docker
View options for a specific command:
docker docker-subcommand --help
Get system-wide Docker information:
docker info
Step 5: Working with Docker Images
Docker containers are built from images. Let's explore how to work with them.
Pulling and Running a Test Image
Verify Docker Hub access by running the hello-world
image:
docker run hello-world
This downloads the image and runs a container, printing a test message.
With these steps, you've successfully installed Docker, understood basic commands, and run your first container. Now you're one step closer to mastering containerization on Ubuntu.