YouTube Icon

Code Playground.

How to Install and Use Docker on Ubuntu 18.04


How to Install and Use Docker on Ubuntu 18.04

Docker is a containerization innovation that permits you to rapidly construct, test, and convey applications as compact, independent holders that can run essentially anyplace. Docker has gotten the true norm for holder arrangement, and it is a fundamental instrument for DevOps engineers and their consistent joining and conveyance pipeline. 

In this instructional exercise, we'll cover how to introduce Docker on a Ubuntu 18.04 machine and investigate the essential Docker ideas and orders. 


Prior to proceeding with this instructional exercise, ensure you are signed in as a client with sudo advantages . All the orders in this instructional exercise should be run as a non-root client. 

Installing Docker on Ubuntu

In spite of the fact that the Docker establishment bundle is accessible in the authority Ubuntu 18.04 store, it may not generally be the most recent variant. The prescribed methodology is to introduce the most recent Docker bundle from the Docker's vaults. 

Enabling Docker repository

Start by refreshing the bundles rundown and introducing the conditions important to add another archive over HTTPS: 

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

Import the archive's GPG key utilizing the accompanying twist order: 

curl -fsSL | sudo apt-key add -

Add the Docker APT archive to your framework: 

sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"

Installing Docker CE

Since the Docker store is empowered, you can introduce any Docker variant you need. 

To introduce the most recent rendition of Docker utilize the order beneath. On the off chance that you need to introduce a particular Docker form, avoid this progression and go to the following one. 

sudo apt update
sudo apt install docker-ce

To introduce a particular adaptation, first rundown the accessible forms in the Docker archive: 

apt list -a docker-ce

The order prints the accessible Docker variants in the subsequent section. 

docker-ce/bionic 5:18.09.7~3-0~ubuntu-bionic amd64
docker-ce/bionic 5:18.09.6~3-0~ubuntu-bionic amd64
docker-ce/bionic 5:18.09.5~3-0~ubuntu-bionic amd64

For instance, to introduce adaptation 18.09.6 you would type: 

sudo apt install docker-ce=5:18.09.6~3-0~ubuntu-bionic

To forestall the Docker bundle from being consequently refreshed, mark it as kept down: 

sudo apt-mark hold docker-ce

When the establishment is finished, the Docker administration will begin consequently. You can confirm it by composing: 

sudo systemctl status docker

The yield will look something like this: 

? docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor p
   Active: active (running) since Tue 2019-07-02 11:28:40 UTC; 15min ago
 Main PID: 11911 (dockerd)
    Tasks: 10
   CGroup: /system.slice/docker.service

Executing docker command without sudo

As a matter of course, running Docker orders requires chairman advantages. 

To run Docker orders as a non-root client without prepending sudo you need to add your client to the docker gathering. This gathering is made during the establishment of the Docker CE bundle. To do that run the accompanying order: 

sudo usermod -aG docker $USER

$USER is a climate variable that holds your username. 

Log out and log back in to invigorate the gathering enrollment. 

To confirm that Docker has been effectively introduced and that you can run docker orders without prepending sudo, run: 

docker container run hello-world

The order will download a test picture, run it in a holder, print a "Welcome from Docker" message and exit. The yield should resemble the accompanying: 

Upgrading Docker

At the point when another Docker rendition is delivered you can refresh the bundle utilizing the standard update measure: 

sudo apt update
sudo apt upgrade

Uninstalling Docker

Prior to uninstalling Docker eliminate all holders, pictures, volumes, and organizations . 

You can uninstall Docker as some other bundle introduced with adept: 

sudo apt purge docker-ce
sudo apt autoremove

Docker Command-Line Interface

The Docker CLI order takes this structure: 

docker [option] [subcommand] [arguments]

To list all accessible orders type docker without any boundaries: 


In the event that you need more assistance on any [subcommand], you can utilize the - help switch as demonstrated as follows: 

docker [subcommand] --help

Docker Images

A Docker picture is comprised of a progression of filesystem layers speaking to guidelines in the picture's Dockerfile that makes up an executable programming application. A picture is an unchanging paired record including the application and any remaining conditions, for example, libraries, doubles, and directions essential for running the application. 

You can think about a Docker picture as a preview of a Docker holder. 

Most Docker pictures are accessible on Docker Hub. The Docker Hub is cloud-based library administration which among different functionalities is utilized for keeping the Docker pictures openly or private stores. 

Search Docker Image

To look for a picture from the Docker Hub library, utilize the inquiry subcommand. 

For instance, to look for a Ubuntu picture, you would type: 

docker search ubuntu

The yield should resemble this: 

Download Docker Image

As should be obvious, the inquiry prints a table with five segments, NAME, DESCRIPTION, STARS, OFFICIAL and AUTOMATED. 

The official picture is a picture that Docker creates related to upstream accomplices. 

Most Docker pictures on Docker Hub are labeled with variant numbers. At the point when no tag is determined, Docker will pull the most recent one. 

docker image pull ubuntu

For instance, to download the most recent authority work of the Ubuntu 18.04 picture, you would utilize the accompanying picture pull order: 

docker image ls

Remove Docker Image

Contingent upon your Internet speed, the download may take a couple of moments or minutes. 

At the point when not indicating a tag, Docker pulls the most recent Ubuntu picture, which at the hour of composing this article is 18.04. 

In the event that you need to download a past Ubuntu discharge , suppose Ubuntu 16.04 then you need to utilize docker picture pull ubuntu:16.04. 

To list all downloaded pictures type: 

docker image rm ubuntu

The yield will look something like this: 

Eliminate Docker Image 

On the off chance that for certain reasons, you need to erase a picture, you can do that with the picture rm [image_name] subcommand: 

docker picture rm ubuntu 

Docker Remove Image 

Docker Containers 

An occasion of a picture is known as a holder. A holder speaks to a runtime for a solitary application, cycle, or administration. 

It may not be the most fitting examination, however on the off chance that you are a developer, you can think about a Docker picture as class and Docker holder as a case of a class. 

We can begin, stop, eliminate, and deal with a compartment with the docker holder subcommand. 

Start Docker Container

The accompanying order will begin a Docker compartment dependent on the Ubuntu picture. In the event that you don't have the picture locally, it will download it first: 

docker container run ubuntu

From the outset sight, it might appear to you that nothing occurred by any means. Indeed, that isn't correct. The Ubuntu compartment stops following booting up on the grounds that it doesn't have a long-running cycle, and we didn't give any order. The holder booted up, ran a vacant order, and afterward left. 

The switch - it permits us to cooperate with the holder through the order line. To begin an intelligent compartment type: 

docker container run -it ubuntu /bin/bash
[root@719ef9304412 /]#

As should be obvious from the yield above, when the compartment is begun, the order brief is changed. This implies that you're presently working from inside the holder . 

Rundown Docker Containers 

To list dynamic holders, type: 

docker holder ls 

List Docker Containers

On the off chance that you don't have any running compartments, the yield will be unfilled. 

To see both dynamic and idle compartments, pass it the - a switch: 

docker container ls

Docker List All Containers 

docker container ls -a

Remove Docker Containers

To erase at least one compartments duplicate the holder ID (or IDs) and glue them after the holder rm subcommand: 

docker container rm c55680af670c


You have figured out how to introduce Docker on your Ubuntu 18.04 machine and how to download Docker pictures and oversee Docker compartments. You may likewise need to find out about Docker Compose , which permits you to characterize and run multi-holder Docker applications. 

This instructional exercise scarcely starts to expose the Docker biological system. In a portion of our next articles, we will keep on plunging into different parts of Docker. To become familiar with Docker look at the official Docker documentation . 

On the off chance that you have any inquiries, if it's not too much trouble leave a remark beneath.