+1 (506) 500-5957 sales@monovm.com Get US VPS for 50% OFF!

How to Install Docker

In today's article, we will show you a step-by-step tutorial on how to install Docker on both Windows and Linux.

Posted: 10 Feb, 21 Updated: 14 Dec, 21 by Antoniy Yushkevych 9 Min

List of content you will read in this article:

Today, Docker is the latest technology that is gaining popularity within the market. It provides you a platform to create containers to run application deployments efficiently. Docker is an open-source technology that converts large extended applications into microservice within the containers and runs them on a different platform without worrying about the underlying infrastructure. With Docker, you do not have to worry about resource management as the resources are being used from the OS kernel resulting in less resource consumption. You can implement Docker within your DevOps pipeline from the starting phase of the application till its deployment in the production environment. Docker can be used as a virtual machine but does not exactly is a virtual machine. Virtual machines are hard to handle, while Docker is easy to implement and operate.

With the help of containers, you can isolate your applications and run them on any platform that shares the same OS kernel. Containers provide you space where you can bundle your applications along with the required libraries. It is easy to handle a limited number of containers at your disposal, but having thousands of containers might be a challenging task to operate. We require some container management tools that help in creating and deploying containers. Thus Docker comes to a picture. 

Docker has gained popularity immediately after its launch in 2013 as an open-source project. It has provided momentum to containerization and microservices concept. As Docker is cross-platform compatible, we will learn how we can install Docker on Ubuntu and Windows servers in the below article.

  • The process to install Docker on Ubuntu 18.04
  • The process to install Docker on Windows.

 

Installing Docker is a process of few simple steps and below are prerequisites of installing it:

  • You must have Ubuntu 18.04 64-bit operating system installed.
  • You need a user account with sudo privileges for running the Docker commands.
  • You should have a basic knowledge of command-line/terminal (CTRL-ALT-T or Applications menu > Accessories > Terminal) for running Docker’s necessary commands like installing and setup.
  • You should have a repository for storing Docker software; this step may be optional.

Before moving forward, check for the version of the Docker installation package. If you do not have the latest version of software installed on your system, you must install it from the repository. You can even validate the download using the new package source and GCP key.

 

Step 1- Run Update for the Packages

If the system and packages are not updated, run the following commands for seamless Docker installation.

sudo apt update

sudo apt upgrade

 

Step 2- Get the Required Packages

Run the following command to install the necessary Docker packages. 

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

 

where:

  • apt-transport-https –it will ensure that http transfer is done transferring the files and data.
  • ca-certificates – it will check the security certificates for the web browser and your machine 
  • curl – transmits the required data
  • software-properties-common – to manage the software, it will add the script using this parameter.

 

Step 3- GCP Key is Added.

The following command will add the GCP key.

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

 

Step 4- Docker Repository is Added to the APT Sources.

The repository is added to make the installation process smoother and ensure that the official method is considered for Docker installation.

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

 

Step 5- Update the Package Database   .

After the repository has been added, next update the package list using that latest repository. Run the following command:

sudo apt update

 

Step 6- Confirming the Installation of the Official Docker Repo

Confirm the installed Docker’s version by running the following command.

apt-cache policy docker-ce

 

Step 7- Installing Docker

Run the following command to start the installation with your choice of Docker’s version.

sudo apt install docker-ce=

 

Step 8- Checking Docker’s Status

Run the following command to check the running status of the Docker.

sudo systemctl status docker

 

Step 9- Start Your Docker

Execute the commands shown below to start and enable the Docker on your system.

sudo systemctl start docker

sudo systemctl enable docker

 

Step 10- Checking the Installed Docker’s Version.

You can confirm the version of the installed Docker by running the following command.

docker --version

 

You may not be able to run Docker directly on Windows 10, but you can run Linux containers on Windows. You can set up a Linux VM on Windows home to run the Docker images and commands. Below are some requirements.

Software requirements for creating and running Docker:

  • Docker Machine: to install the Docker Engine on virtual hosts
  • Docker Engine: it will run on top of the Linux Kernel to build and run the containers
  • Docker Client: a CLI tool to run Docker Engine commands via REST API
  • Docker Compose: a tool to define and run the multi-container applications

To run Linux containers on Docker, you will need a Linux kernel. To make it work on Windows, you have to set a Linux VM to work on Windows 10. Once you install the Docker machine, you will require SSH for Docker’s client and Docker engine communication on a local or remote server. The process of creating and running images will be done in VM but not on the host.

 

Step 1- Install the Software.

  • Install the terminal (Git Bash for Windows) to run Docker commands.
  • Install package manager (chocolatey) for Windows. 
  • Install VirtualBox with its extensions or can run the following command to install.

C:\ choco install virtualbox

 

Step 2- Setting up the Docker Engine

  • Run the following command from an elevated PowerShell terminal to install Docker Machine.

C:\ choco install docker-machine

  • Install Docker Engine using the following command from the Git Bash terminal. It will download the Linux image with Docker Engine and run it using VirtualBox. Run the folowing command.

$ docker-machine create --driver VirtualBox default

  • Set the port details for running Docker containers. Launch the Oracle VM VirtualBox, and select the default VM. Go to Settings -> Network -> Adapter 1 -> Port Forwarding. 

  • Now mount volumes for the Docker on your hard drive. By default, you can use C://Users/ directory for mounting volumes to your Docker. If you want to add a different path, then go to VM VirtualBox -> select default VM -> settings -> shared folders and enter new fields by clicking plus. Then enable the permanent option.

  • You can avoid invalid settings from the above image by increasing the video memory under the display tab. 
  • Run the following command to start the Linux VM on your system. This process will take time for the boot.

$ docker-machine start vbox

  • Set the Docker environment variables for Docker client and compose to communicate with Docker Engine. 

# it will display the docker-machine instance settings

$ docker-machine env default

 

# it will set the environment variables 

$ eval $(docker-machine env default --shell linux)

 

Step 3- Setting up the Docker Tools.

Run the commands shown below to install some tools using PowerShell in the admin mode. These tools come with a Docker package for Windows. As you cannot run the installer on Windows, you have to install tools with chocolatey.

C:\ choco install docker-cli

C:\ choco install docker-compose

 

Step 4- Ensuring Docker installation is running successfully.

Run the following Linux commands.

# Starting the Docker VM using the below command

$ docker-machine start default

 

# Confirming Docker VM is running using the below command

$ docker-machine ls

 

# Configuring the Docker Environment for using the Docker VM

$ eval $(docker-machine env default --shell Linux)

 

# Confirming the Docker is connected. 

$ docker info

 

# Running hello-world docker image. 

$ docker run hello-world

 

If you get the output for all the above commands, you have successfully installed Docker on Windows. 

 

Docker has become an essential part of every business working on deploying applications. Docker offers you cross-platform compatibility thus can be installed on Linux or Windows as per your business requirement. In the article, we have mentioned easy steps to install Docker with required prerequisites. Let us know your feedback or queries, if any, in the comments below. 

Antoniy Yushkevych

Antoniy Yushkevych

Master of word when it comes to technology, internet and privacy. I'm also your usual guy that always aims for the best result and takes a skateboard to work. If you need me, you will find me at the office's Counter-Strike championships on Fridays or at a.yushkevych@monovm.com