Open In App

How To Install and Use Docker on Ubuntu 22.04

Last Updated : 22 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Docker is a platform used by developers to automate the deployment of applications within containers. The containers include all the necessary components for the application to run, ensuring consistent behavior across various environments. In this guide, we'll walk through the process of installing Docker on Ubuntu 22.04, explore key Docker concepts, and how to use Docker.

What is Docker?

Docker is a platform that supports container creation, deployment, and management. Containers are self-contained environments that package an application and all its dependencies together, making it easy to move applications between different environments without worrying about social issues.

Key Terminologies

  • Image: A lightweight, self-contained, executable package that contains everything required to run a software application, including the code, runtime, libraries, environment variables, and configuration files.
  • Container: A running instance of a Docker image. Containers operate in isolation from each other and the host system.
  • Docker Hub: A cloud-based repository where Docker users can store, share, and access Docker images.
  • Dockerfile: A script that outlines a set of instructions for building a Docker image.

Prerequisites

  • A system running Ubuntu 22.04.
  • A user account with 'sudo' privileges.
Check your  lnux version using cat /etc/os-release command

Step-by-Step Process to Install Docker on Ubuntu 22.04

In this section, we will discuss the step-by-step installation of docker using the 'apt' repository

Step 1: Update Your System

First, update your system's package index to ensure that it is up-to-date. Open the terminal in your Linux system and run the bash commands shown below.

sudo apt update
sudo apt upgrade

Step 2: Set up Docker's 'apt' repository

Run the bash commands shown below in your Linux terminal to set up Docker's 'apt' repository.

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
Setting up Docker's 'apt' repository

Step 3: Install the Docker packages

To install the Docker packages, run the bash command shown below in the terminal:

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Installing the latest version of Docker packages

Step 4: Verify Docker Installation

To verify that Docker is installed and running, run the bash command shown below in the terminal:

sudo systemctl status docker
verifying the Docker installation and status

Basic Docker Commands

1. Pull an Image from Docker Hub

  • To pull an image from Docker Hub, use the 'docker pull' command:
sudo docker pull hello-world
docker pull command execution in Linux terminal

2. Run a Container

  • Once the image is pulled, you can create and run a container using:
sudo docker run hello-world

This command runs the 'hello-world' container, which prints a welcome message and exits.

docker run command execution in Linux terminal

3. List Running Containers

  • To list running containers, use:
docker ps
docker ps command execution in Linux terminal

Conclusion

Docker is a powerful tool for building, deploying, and managing applications in a distributed environment. After completing this tutorial, you should have Docker installed on your Ubuntu 22.04 system and be familiar with basic Docker commands. Docker's ability to package applications and their dependencies into containers makes it an essential tool for developers and administrators.


Next Article
Article Tags :

Similar Reads