How to Install Docker on Ubuntu: A Step-by-Step Guide

How to Install Docker on Ubuntu

Because Docker ensures consistency across several settings, it has completely changed the way developers deploy apps. The procedure of installing Docker is simple if you’re running Ubuntu, one of the most widely used Linux variants worldwide. You will be able to access a plethora of containerized applications with ease by following the instructions in this article to install Docker on your Ubuntu system.   

What is Docker?  

Docker Logo

Any program can be developed, shipped, and operated inside of containers using the Docker platform. An open platform for creating, distributing, and executing applications is called Docker. It lets you swiftly deliver software by separating your apps from your infrastructure. You may use Docker to manage your infrastructure in the same manner that you do your applications. You may cut down on the time it takes to ship, test, and deploy code in production by utilizing Dockers’ techniques.  

Using Docker, an application can be easily packaged and launched in a container—a loosely isolated environment. On a certain host, you can execute multiple containers at once thanks to the isolation and security. You don’t have to depend on what’s installed on the host because containers are lightweight and come with everything you need to run the application. As you work, you can share containers and make sure that everyone you share with has access to the same, uniform container.   

Docker gives you the tools and a platform to control your containers’ lifecycle:   

  • a. Use containers for developing your application and its supporting elements.  
  • b. Your application is distributed and tested using the container as the unit.   
  • c. When you’re prepared, launch your application as an orchestrated service or in a container into your production environment. Regardless of whether or not your production setting is a cloud provider, a local data center, or a combination of the two, this operates in the same way.   

What are the uses of Docker?  

  1. Delivering your applications in a timely and reliable manner: By enabling developers to operate in standardized settings with local containers that host your applications and services, Docker simplifies the development lifecycle. Workflows involving continuous integration and continuous delivery (CI/CD) benefit greatly from containers.   
  1. Scaling and deploying responsively: Workloads can be carried out anywhere thanks to Docker’s container-based technology. A developer’s laptop, real or virtual machines in a data center, cloud providers, or a combination of environments can all execute Docker containers. Because of its lightweight design and mobility, Docker also makes it simple to manage workloads dynamically, quickly scaling up or down services and applications based on business requirements.  
  1. Utilizing the same hardware for additional tasks: Docker is quick and lightweight. It offers a practical, affordable substitute for virtual machines based on hypervisors, allowing you to utilize more of your server’s capacity to meet your company’s objectives. When you need to accomplish more with fewer resources in small and medium operations and high-density situations, Docker is ideal. 

The Architecture of Docker :  

A client-server architecture is used by Docker. The Docker daemon, which builds, manages, and distributes your Docker containers, is the one with whom the Docker client communicates. A Docker client can be connected to a distant Docker daemon, or the daemon and client can operate on the same machine. UNIX sockets, a network interface, or a REST API are how the Docker client and daemon exchange information. Docker Compose is an additional Docker client that enables you to interact with apps that are composed of many containers.   

Docker Daemon:  

Docker objects including images, containers, networks, and volumes are managed by the Docker daemon, or dockerd, which also responds to Docker API calls. To manage Docker services, a daemon can converse with other daemons.  

Docker Client:   

For many Docker users, the main interface to interact with Docker is the Docker client (docker). The client transmits commands to dockerd, which executes them when you use commands like docker run. The Docker API is used by the docker command. Multiple daemons can be in communication with the Docker client.  

Docker Desktop:   

You can create and distribute containerized apps and microservices with Docker Desktop, an easy-to-install program for Linux, Windows, and Mac. The Docker daemon (dockerd), the Docker client (docker), Kubernetes, Credential Helper, Docker Compose, and Docker Content Trust are all included with Docker Desktop. See Docker Desktop for further details.  

Docker registries:   

Docker images are kept in a registry. Docker searches Docker Hub by default for images, and Docker Hub is a publicly accessible registry. Even managing one’s private registry is possible.  

The necessary images are pulled by Docker from your configured registry when you execute the docker pull or docker run commands. Docker pushes your image to the registry that you have configured when you implement the docker push command.   

Docker Objects:   

  1. Creating and utilizing images, containers, networks, volumes, plugins, and other things is what Docker is all about. A quick rundown of a few of such items is provided in this section.  

Image:  

An image is a read-only template that contains Docker container creation instructions. An image is frequently derived from another image with some further editing. You may, for instance, create an image that is based on the Ubuntu image and includes your application and the Apache web server installed, together with the configuration information required for your application to function.   

You have the option to either produce your images or limit your usage to those made by other people and listed in a register. You construct a Dockerfile with a straightforward syntax to define the procedures required to produce and run your image. A layer is created in the image for every instruction in a Dockerfile. Only the modified layers are rebuilt when you make changes to the Dockerfile and rebuild the image. This contributes to the lightweight, small size, and speed of pictures in comparison to other virtualization systems.   

Containers:   

An executable instance of an image is called a container. The Docker API and CLI allow you to create, stop, transfer, and destroy containers. A container can have storage attached to it, be connected to several networks, or even have a new image created depending on its existing state.  

A container’s default level of isolation from its host computer and other containers is rather high. The degree of isolation between a container’s network, storage, and other underlying subsystems and the host computer or other containers can be adjusted.   

An image and any configuration variables you give it during creation or startup define a container. Any modifications made to a container’s state that aren’t kept in persistent storage vanish when it is deleted.   

Methods to Install Docker on Ubuntu 20.04 and 22.04 

Required conditions for installation-  

  • Installed either Ubuntu 20.04 or 22.04.  
  • An account that is used as an administrator.  
  • Terminal access (Ctrl + Alt + T).   

Ubuntu is the leading platform to manage Docker and Kubernetes containers. This is because Ubuntu runs containers at scale, is fast, safe, and open-source, and powers millions of machines around the world.   

This article will discuss two methods for install Docker on Ubuntu:   

  • From the official Docker repository, assuring the most recent Docker version.  
  • From the normal Ubuntu repositories, resulting in a simpler installation.  

Method 1: Installing Docker from the Official Repository   

Installing Docker from the Official Repository 

Install Docker from the official Docker repository to acquire the most recent stable version. To access the official Docker repository, install Docker after adding the new package source to Ubuntu. Follow the steps below-  

Step 1: Make Package Repository Updates   

To make sure the most recent prerequisite packages are installed and to update the system’s package repository, run the following command:  

sudo apt update  

To continue with the upgrade, type your root password when requested and hit Enter.   

Step 2: Installing the Necessary Packages   

To use packages over HTTPS, the apt package manager needs to install a few required packages on the system. To enable Ubuntu to use the Docker repository over HTTPS, run the following command:  

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

The given command:   

  • permits apt to send data and files over https.  
  • permits security certificate verification by the system.   
  • Installs a data-transfer program called curl.   
  • include scripts for managing software.   

Step 3: Include the GPG Key   

A GPG key confirms a software package’s legitimacy. To add the GPG key for the Docker repository to your system, run:  

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –  

OK should appear in the output, confirming that it is valid.   

Step 4: Add the Docker Repository   

To include the Docker repository in apt sources, execute the following command:  

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

The command updates the package database with the most recent Docker packages and adds the official Docker repository.   

Step 5: Choose the Installation Source   

To confirm that the Docker installation source is the Docker repository and not the Ubuntu repository, run the apt-cache command. With the Docker packages we have earlier added, the apt-cache tool searches the apt package manager’s package cache.  

Execute the next command:   

apt-cache policy docker-ce  

In the additional source repository, the output will indicate which version is the most recent.   

Step 6: Installing Docker.   

Run the following to install Docker:  

sudo apt install docker-ce –y  

Wait until the installation is finished.   

Step 7: Verify the Docker Status   

Verify that Docker is set up, the daemon is running, and the process is set to launch at boot. Execute this command:  

sudo systemctl status docker  

The output will indicate that the Docker daemon is currently operational.   

Method 2: Install Docker using the Default Repositories

Install Docker Using the Default Repositories

You can also make use of the default Ubuntu repository to install Docker on Ubuntu. While the installation procedure is simpler, the Docker package can be out of date. Use the default repository to install Docker and follow the instructions below if you don’t care to have the most recent version of the program.   

Step 1: Update the Repository make sure to perform the following commands to update the local system package repository:  

sudo apt update  

When prompted, enter the root password and wait for the procedure to be completed.   

Step 2: Install Docker   

The command to install Docker is as follows:  

sudo apt install docker.io –y  

When the -y switch is specified, installing any prompts will automatically result in a YES response.   

Step 3: Install dependencies.   

To install every package required by Docker, do the subsequent command:  

sudo apt install docker  

The command uses the Snap package manager to install all of the requirements.   

Step 4: Verify Installation   

Use the status command to see if Docker was installed correctly, or look up the version of the application. Run: to view the status of the Docker daemon.  

sudo systemctl status docker  

Alternatively, run the following to verify the version of the program:   

docker –version  

How to Use Ubuntu with Docker?  

Run the docker command in the terminal to access all Docker information, including syntax, options, and commands:  

Docker   

Conclusion

In this article, we provides a step to step guide for users who are seeking guidance in installing Docker to their Ubuntu Operating System. We have covered both methods to install Docker. By following the specified steps defined in this article a user will be able to install docker for their use. We covered several topics to help individuals have a basic understanding of Docker. You can also check out our guide on how to install VS code on Ubuntu.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top