DROP A QUERY

How to Install Docker on Ubuntu 20.04

StarAgilecalenderJuly 15, 2022book18 minseyes2046

Docker is one of the platforms that help you to package your applications and make you able to deliver them to the cloud. The main thing is there are no dependencies when you are delivering them to the cloud. Like this, there are many features of this platform, and if you are looking to use this platform and want to know about how to install docker on ubuntu, then you are reading the right page on the internet today. Here not only we are going to let you know the steps that you can follow to install this application in your system, but we are also going to let you know how you can use it once it is installed on your machine. This page will guide you to use this application to its fullest potential. But first, we are going to look at some of the basics of docker and how this application is beneficial for various enterprises. Also, by the end of this blog, you will find the section where you can look for DevOps Training so that you can move ahead in your career too.

How docker is used and what are its benefits?

If you are looking for a platform that could help you with cloud-based applications, then going for docker can be the best step for the same applications. Using this platform, you will be able to create isolated environments and also be able to automatically scale them up or down whenever you need to. Some benefits include:

  1. Caching the cluster of containers
  2. Flexible resource sharing
  3. Option to scale- there could be as many containers in the single host
  4. The hardware on this platform can run is much cheaper than the servers that are needed otherwise
  5. You can have fast deployment, also with the ease of creating new instances, and also the migrations become faster
  6. You can maintain and move the application on the cloud at an ease
  7. Get better security, there are fewer software dependencies and there will be less access needed to work with the code that is running inside of the containers.

So, if you are impressed with these benefits and want to create an infrastructure of your own, then you can have this platform downloaded. Below we are going to mention those steps and prerequisites for the installation so that you can take this step without any issues.

What are the prerequisites to install docker on ubuntu?

To install docker on ubuntu, there are some system requirements that you need to fulfill.

Linux Ubuntu as the OS (other operating systems are supported as well). The system should have an absolute minimum of 512MB RAM but the recommendation is for 2GB.

OS: Linux Ubuntu

Memory: 512MB RAM (2GB Recommended)

Disk: To make sure that you do not face any issues, use the disk space that fits with your docker containers.

CPU: This depends on the applications that you want to run in the containers that you are going to use with docker.

Steps to install docker

You can download the docker installation package that is available on the official Ubuntu repository. But to ensure that you are installing the latest version, install it from the official Docker repository. To make that possible, we need to add a new package source, then add the GPG key from the docker to ensure that the downloads that we are doing are valid. After that, we need to install the package.

Update the existing lot of packages available with the command

$ sudo apt update

Now you need to install the few prerequisites that will let the apt use the packages over HTTPS using the command

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

Add the GPG Key which you need to install the application from the official Docket repository in your system.

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

Now add the docker repository to the available APT sources.

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionicstable"

Now you need to update the package database with the docker database. You can do this from the newly added repo in your system.

$ sudo apt update

You need to make sure that you are about to install the application from the Docker repo instead of the default Ubuntu repo. Make a point of it.

$ apt-cache policy docker-ce

Although the version that you are going to see on the screen is different from the output mentioned below

The output of apt-cache policy docker-ce

$ docker-ce:

  Installed: (none)

  Candidate: 18.03.1~ce~3-0~ubuntu

  Version table:

     18.03.1~ce~3-0~ubuntu 500

    500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages

Here you can notice that the docker-ce is not installed yet, but the candidate that is coming on the screen is from the docker repo for Ubuntu 18.04. With this, you can proceed and install docker on your system.

$ sudo apt install docker-ce

After this command, the docker will be installed in your system. The daemon will be started and the process will be enabled to start on boot. You can use the below-mentioned command to see if it is running or not.

$ sudo systemctl status docker

With this, now your service is active and running. When you are having this installed on your machine, not only you are going to get the docker service (daemon) but you are also going to have the docker command-line utility, also known as the Docker client. You can learn how you use that command line and get a grasp on this concept with the best training material online.

How to execute the docker command without sudo?

By default, the docker command can only be run by the root user or the user in the docket group. This is created automatically during the installation. So, if you attempt to run this command without using sudo or without being in the docket group, you will not be able to access it. If you want to not use sudo every time you are going to use the docket command, then you should add your username to the docker group using the following command.

sudo usermod -aG docker ${USER}

You need to log out of the server and back in, to apply for the new group membership by typing

$ su - ${USER}

Now you can add your username and password to continue. You should now confirm if your user is added to the group with

$ id -nG

You will find your user’s name on the output screen. Moreover, you can declare the Sudo explicitly if you are not logged in as that user by using

$ sudo usermod -aG docker username

Now we are going to explore how you use the docker command in your system.

When you are using docker commands, then you need the syntax that is mentioned below

$ docker [option] [command] [arguments]

There are many subcommands that are present in docker and if you wish to view them, then you need to type:

$ docker

  • docker run – Runs a command in a new container
  • docker start – Starts one or more stopped containers
  • docker stop – Stops one or more running containers
  • docker build – Builds an image from a Docker file
  • docker pull – Pulls an image or a repository from a registry
  • docker push – Pushes an image or a repository to a registry
  • docker export – Exports a container’s filesystem as a tar archive
  • docker exec – Runs a command in a run-time container
  • docker search – Searches the Docker Hub for images
  • docker attach – Attaches to a running container
  • docker commit – Creates a new image from a container’s changes

These are some common sub-commands that are widely used in the docker environment.

With this, you will get the list of subcommands that are available for you. But if you wish to view the options available for any specific command, then you can type

$ docker docker-subcommand –help

And if you wish to view the system-wide information about docker, you can use:

$ docker info

How to run a docker container in Ubuntu?

There are some steps that you need to follow when you are going to run the containers present in your docker application. You can follow the below-mentioned steps:

Step 1: Move the container infrastructure to the cloud

When you have deployed the application, then you will be able to see that the application is deployed to your choice of cloud. One of the best ways to deploy the containers is by using Kubernetes. Kubernetes is a container orchestration solution that helps you to deploy and operate various containers and their clusters that are used for the deployment of containers of various different kinds. This container cluster is managed by Kubernetes and this is widely used.

Step 2: Monitor the environment

There are various providers that we can use to monitor the environment and some examples for the same are Azure Information Protection (API), IBM DataSmart, and Splunk. We can understand this with the help of an example. If we need to create the machine event for our environment, we can take the help of the following API requests. Using these API requests, we will be able to manage our environment, and also send the report. Along with this, we can delete or update the system as per the need. This is just a small example of the options that are given. If you wish to learn more about these options, you can see and learn from the provider’s documentation.

Step 3: Configure the system

There are various things needed in the system to run various components. After we have deployed our application, we need to configure the system as per the requirements. Using the Dockerfile, we will need to configure the production environment in our system. This file is responsible and it is a bash script that we can use to create our system. This script helps in providing the configuration that is needed for various components and to deploy the application as well.

Step 4: Adding the vault

One of the main functions of the vault is to protect, secure, and give access to the source code. It helps in storing the secrets, credentials, and secret keys, and this is widely used for various environments that are present in your system. If you are using the vault, then you can configure the specific user or the group, and give them access to various source code repositories and databases.

If you wish to add the vault to your system, you need to make changes in your project’s source code and add the source files in the right place. These files are in the /vault directory. Not only this, you need to add various dependencies to the vault.

To add the necessary Vault source files to the project, we can do the following:

$ git add vault/cache.yml vault/source.json vault/rpc.yml $ git add vault/provision.yml $ git addvault/user.yml $ git commit -m "Add Vault Source Files."

Step 5: Run the application

Now we are going to run the docker file from the root directory to run the application.

$ docker-compose run app

This command will help to run the docker file from the /vault directory.

Step 6: Start The machine

After you are done with the command, the application will run. After it gets started, you are going to have a primary and straightforward API in front of you.

Step 7: Deployment to the machine

Now that you have an up and running application, you might need to deploy the application to your machine. You can use the below-mentioned command to do the same.

$ docker-compose up -d

With this, you will be able to have the instance that is running the application that you need.

Step 8: Restart the machine

Now if you wish to restart the instances, then you can use the same command

$ docker-compose down -d

With this, the instance will now be running.

Step 9: View State

After the application is running, if you want to show the machine states of the application, then you can use the below-mentioned command for the same.

$ docker-compose ps

After this, you will be able to see the state of the application that is running on your machine.

Step 10: Inspect /vault/code

To inspect the contents of our source code, we can use the following command:

$ docker-compose exec /vault/code

This command will output the content of our /vault/code directory. Using this, you can see what is there in the directory.

Wrapping it up

It is indeed a fact that with the use of docker, you can very easily move the application to any cloud and have independence of your own. In this article, we have learned all about the steps that you can follow to install docker on ubuntu 20.04. After you have docker installed on your machine, you can go for docker container deployment. There are various cloud hosting servers that are useful for the same. We have also seen how you can run this application in your system and see what are the available subcommands that you can use on your machine. With various examples and other experiences, you will be able to see how these containers work and get your hands-on experience with them.

Become a DevOps practitioner

If you are piqued interest while learning about docker in this blog, then you set the path for yourself towards becoming a DevOps practitioner. There are various opportunities that are available if you are following the right path. With DevOps certification from the best platform online like StarAgile, you are going to get quality training that would boost your knowledge and add a high repute certification to your profile. The team is very professional and the courses are designed in such a way that everyone is able to ace them. So, if you wish to make a career in this field, now is just the right time. You can start today and get your DevOps certification to open various doors of opportunity.

Difference Between Agile and SAFe Agile

calender13 Mar 2020calender mins

Scrum Master Certification Cost

calender12 Nov 2019calender mins

Do We Need an Agile Coach

calender27 Jun 2019calender mins

Upcoming DevOps Training Workshops:

NameDate-
DevOps Certification Training20 Aug-18 Sep 2022,
weekday
View Details
DevOps Certification Training27 Aug-09 Oct 2022,
weekend
View Details
DevOps Certification Training03 Sep-02 Oct 2022,
weekend
View Details

Keep reading about

Card image cap
DevOps
reviews2171
Top 10 DevOps programming languages in 20...
calender18 May 2020calender mins
Card image cap
DevOps
reviews2096
Top 9 Devops Engineer Skills
calender18 May 2020calender mins
Card image cap
DevOps
reviews2084
Best DevOps Tools in 2022
calender18 May 2020calender mins

We have
successfully served:

3,00,000+

professionals trained

25+

countries

100%

sucess rate

3,500+

>4.5 ratings in Google

Drop a Query

Name
Email Id
Contact Number
City
Enter Your Query