Home Technology Beginner’s Guide to Installing Docker on Ubuntu 22.04: A Step-by-Step Guide

Beginner’s Guide to Installing Docker on Ubuntu 22.04: A Step-by-Step Guide

by karani

Installing Docker on Ubuntu 22.04 is a straightforward process that can significantly enhance your development environment by enabling containerization. This guide will take you through the steps to install Docker, ensuring even those new to Docker can follow along.

Prerequisites

  • Ubuntu 22.04 installed on your system.
  • A user account with sudo or root access.
  • An active internet connection.

Step 1: Update Your System

Before installing any new software, it’s a good idea to update your system to ensure you have the latest versions of existing packages. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade -y

Step 2: Install Required Packages

You need to install a few packages that allow apt to use packages over HTTPS:

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

Step 3: Add Docker’s Official GPG Key

Docker signs its packages with GPG to ensure their integrity. You must add Docker’s 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

Step 4: Add Docker Repository to APT Sources

Now, add the Docker repository to APT sources to ensure you get the software from the official source:

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 Engine

Update your apt package index, and install Docker Engine (this includes docker-ce, docker-ce-cli, and containerd.io):

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io -y

Step 6: Verify Docker Installation

To ensure Docker has been installed correctly and is running, execute:

sudo systemctl status docker

You should see output indicating that Docker is active (running).

Step 7: Running Docker as a Non-root User

By default, running Docker commands requires root privileges. To avoid this and enable Docker commands without sudo, add your user to the Docker group:

sudo usermod -aG docker ${USER}

To apply these changes, log out and back in, or you can type the following to apply the changes in the current session:

newgrp docker

Step 8: Test Docker Installation

Test your Docker installation by running the hello-world image:

docker run hello-world

If Docker is correctly installed, you will see a message indicating that your Docker installation is working.

Step 9: (Optional) Install Docker Compose

Docker Compose is a tool for defining and running multi-container Docker applications. To install it, run:

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Verify the installation with:

docker-compose --version

Congratulations! You’ve successfully installed Docker on Ubuntu 22.04. You’re now ready to explore the world of containerization. Docker simplifies the deployment of applications, making it easier to package and distribute software across different environments. Happy Dockering!

You may also like