How to Install Docker On Ubuntu 20.04 & 22.04

Docker, an open-source platform, offers a standardized and efficient approach to packaging, distributing, and running applications in isolated environments using containers.

Containers provide enhanced portability and resource efficiency and depend more on the host operating system than virtual machines. The host with Docker installed is referred to as the Docker engine.

Docker employs OS-level virtualization for container runtime environments. It acts as a Platform as a Service (PaaS). Docker containers can seamlessly build upon and interact with each other, supporting applications like Apache servers or MySQL databases.

Unlike traditional virtual machines, Docker containers do not require a full operating system for execution. Instead, they utilize a shared underlying kernel, enabling the launch of multiple containers for separate servers without extensive OS installations. This is achieved through lightweight Docker images.

Additionally, Docker is a cross-platform undertaking; thus, regardless of the operating system (Linux, Windows, or macOS), the commands remain consistent across all platforms, eliminating container compatibility concerns.

The Essential Components of Docker Include

  • Docker CLI (Command Line Interface)
  • Docker REST API
  • Docker Daemon (Server)

Requirements

  • Installed Ubuntu 20.04 or Ubuntu 22.04.
  • User account with administrative privileges.
  • Continue the steps below to install Docker CE on either Ubuntu 20.04 or Ubuntu 22.04.

Update The System

Make sure your system is up to date.

# sudo apt -y update

Install Basic Dependencies

Before installing Docker on Ubuntu, setting up specific dependencies is essential. Use the following command to install them:

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

Install Docker Community Edition (CE)

Important Note: Before installing a new instance of Docker, it’s essential to eliminate any existing Docker installations. Removing prior Docker versions will not delete images, containers, volumes, or networks you’ve created. To uninstall previous versions, execute the following command:

# sudo apt remove docker docker-engine docker.io containerd runc

To install Docker successfully, you must first import the GPG key for its repository:

# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg

Next, you can add the Docker CE repository to your Ubuntu system.

# sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”

Lastly, Proceed To Install Docker Ce On Ubuntu

# sudo apt update

# sudo apt install docker-ce docker-ce-cli containerd.io

Ensure successful installation by confirming the Docker version:

# docker version

Verify Docker Status

To confirm Docker’s installation, verify that the daemon is running, and ensure the process is enabled to start during boot, execute the following command:

# sudo systemctl status docker

To start the Docker service if it’s not running, you can use:

# sudo systemctl start Docker

To enable the Docker service to start automatically upon boot, execute:

# sudo systemctl enable Docker

Alternatively, verify the program version by running:

# docker –version

Using Docker On Ubuntu

You can access all Docker-related information, including syntax, options, and commands, by executing the docker command in the terminal:

Docker

You can start using Docker by downloading Docker images, creating containers, and managing Docker volumes.

Note: Docker commands must be executed with the sudo prefix on Ubuntu.

Docker containers are constructed upon Docker images, which reside within Docker Hub, a repository dedicated to Docker.

This repository allows the Docker users to host their images on the Docker hub, providing a wide range of images, including Linux distributions and applications.

Use the docker search command to find available images on Docker Hub. The syntax is:

# Sudo Docker Search [Keyword]

To search for [keyword], input the specific keyword you wish to query. For instance, if you want to display all Ubuntu images, execute:

The result will be a list of images with the Ubuntu keyword. If the OFFICIAL column displays the [OK] indicator, the official company responsible for the project’s development uploaded the image.

You can download any desired image using the “pull” option. The syntax is as follows:

# sudo Docker pull [image-name]

After successfully downloading the image, you can use it to launch a container. However, if you try to create a container from an image that hasn’t been downloaded, Docker will download the image first and then proceed to create the container.

To verify the images you’ve downloaded, execute the following command:

# sudo docker images

The command will display a comprehensive list of all downloaded images on your system. In our example, this encompasses a Ubuntu and a MySQL Docker image.

Docker containers are isolated virtual environments created from Docker images. You can use an image you have downloaded or specify its name within the “docker run” command to trigger automatic image download and container creation.

For instance, utilize the hello-world image to download a test image and launch a container. Execute the command below:

# sudo Docker run hello-world

The command prompts Docker to fetch the image from Docker Hub and initiate a container. Upon creation, the container displays the “Hello from Docker” message, explains its functionality, and then terminates the container.

View Docker Containers

A running Docker container is considered active. Listing containers is beneficial as it provides the unique ID and name needed for actions such as starting, stopping, or deleting a container.

To exclusively display active Docker containers, execute:

# sudo docker ps

To display a list of all containers, including those that are not currently active, add the -a flag:

# sudo docker ps -a

Install Docker Compose on Ubuntu 22.04 / 20.04

Installing Docker Compose is not mandatory. If you choose to install it, you can download the latest Compose version onto your Linux machine by running the following commands

: # curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url | grep docker-compose-linux-x86_64 | cut -d ‘”‘ -f 4 | wget -qi –

Make the binary file executable.

# chmod +x docker-compose-linux-x86_64

Move the file to a location within your PATH.

# sudo mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose

Verify the installed version.

# docker-compose version

Add the user to the docker group:

# sudo usermod -aG docker $USER

# newgrp docker

Installing Docker on Ubuntu enables streamlined application deployment, improved resource utilization, and enhanced system security through containerization. By following the steps mentioned in the article, you can easily set up Docker on your Ubuntu system and unlock the benefits of this powerful tool. By harnessing the power of containerization, Docker enables easy application deployment, scalability, and portability.

(Visited 2,099 times, 1 visits today)

Leave a Reply

AlphaOmega Captcha Classica  –  Enter Security Code
captcha      
 

This site uses Akismet to reduce spam. Learn how your comment data is processed.