February 3, 2023

How To Install Docker On Ubuntu 20.04

Abhishek Thakur

Docker is a software framework for for building, running, and managing containers on servers and the cloud.  It’ a freemium service based on other OCI projects. Unlike traditional virtualization method Docker virtualization happens on an OS level rather than depending on hardware. Using Docker you can build an array of sets for each process and deploy them on cloud. Using Docker it is easier to automate the deployment of applications in lightweight containers so that applications can work efficiently in different environments. It also saves a lot of time for configuring system like tradition app deployment methods requires. Another benefit of using docker is that the package is available for all major OS like Windows, Linux and Mac OS. In this guide we will explain how to install Docker On Ubuntu 20.04 and deploy of your first container.

Requirement

Steps To Install Docker From Official Repository

To use the latest version of Docker we are going to use the official Docker repository. You can also use the default Ubuntu repo but the version will not be the latest. SSh into the server and before proceeding with the install update the local package and repo list. To do that run the given commands. When prompted type and continue with the installation.

# apt-get update

# apt-get upgrade

Once the update are finished we can move to the next step to add the required dependencies to run containers. In the terminal windows run the given command to install the required packages.

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

Oce the installation is finished we have to add the Docker gpg repo to our list of repository, in order to download the Docker file. To do that run the given command in terminal

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

# add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable”

Now as the gpg repository is added we can proceed with the installation of Docker using the given command.

# apt install docker-ce -y

After the installation is finished add the logged in user to docker group to use the Docker service without sudo privilege. Run the given command to add the current user to the group.

# usermod -aG docker $root

# newgrp docker

Now we can verify the current installation using the given command

# docker version

Check Docker Version

Working With Docker Images

A Docker image is a file used to run code in a Docker container. Like a template, a Docker image acts as a set of instructions for building a Docker container. A Docker image also serves as a starting point for using Docker. Docker  image is like a snapshot of a virtual machine (VM) environment. These pre configured images speed up Docker builds while increasing reusability and decreasing disk use. A Docker image contains everything needed to run a containerized application, including code, configuration files, environment variables, libraries, and runtime. If your image is deployed in a Docker environment, you can run it as a Docker container. Now as we know how to install Docker,  we can proceed further and search some images from Docker hub. For example if you want a Docker java image you can search it in the Docker hub using the given command.

# docker search java7

Searching Docker image

The given command will return all the images that have been configured and uploaded to Docker Hub having all the necessary packages for java 7. Similarly you can modify your search for different tech stack by replacing java7 with your desired keyword. Another example to this, lets search for a web server image on Docker hub. Also do remember that the docker search images is limited to singular argument so do not put a space between your techstack version. If the Official mark is [OK] that means the image is maintained and uploaded by official company that developed the tech.

# docker search nginx

Docker

Pulling An Official Ubuntu Image From Docker

After searching your desired image you can run the given command to pull it to the docker service. In our case we will be using an CentOs image for example. The given command will pull the latest centos image from the docker repo.

# docker pull centos

Pulling CentOs

Now, to check the downloaded downloaded docker image run the given command in terminal.

# docker images

Docker images

Deploying Your First Docker Container

A Docker container is a virtualized runtime environment used in application development. It is used to build, run, and deploy applications decoupled from the underlying hardware. Docker containers can use a single machine, share its kernel, and virtualize its operating system to run more isolated processes. Running a Docker containers need a runnable image to exist. Containers are dependent on images, because they are used to construct runtime environments and are needed to run an application. In this guide we are going to use the hello-world example. First we need to download the hello-world images from docker hub. To do so run the given command.

# docker pull hello-world

docker hello-world

After it is done successfully we can run the hello-world image. To do so run the given command in terminal.

# docker run hello-world

Docker Run

Finally, the output will print up Hello from Docker! with all the necessary steps docker daemon took to print the output to the clients terminal.

Conclusion

In this guide we explained  how to install Docker on Ubuntu 20.04 and start using Docker to download images and run containers. Next we will talk about its process handling and commands. Till then thank you for your time.


Buy Dedicated Docker Server @  $37.99/m Only

Popular Blog Posts