DOCKER (How to install DOCKER on Linux)

Kasun Dissanayake
5 min readFeb 23, 2020

--

Today we are going to learn how to install Docker on Linux and as always we will go to very basics step by step. At the end of this session, we will also look some useful tips.

In this session we will look at some prerequisites ;

  • Connect to Linux
  • Install Docker
  • Start Docker
  • Stop Docker
  • Uninstall Docker

Let’s get Started

You must be having some Linux system to learn this tutorial because we are going to install Docker to Linux systems. If you do not have a Linux system and you want to do it in hands-on you can get a free Linux instance from Amazon AWS. Use this link to get a free Linux instance from Amazon. You can create a free account and get a free instance.

Connect to Linux

As a part of prerequisites type this command and check information about your operating system.

$ uname -r

OS requirements

To install Docker Engine — Community, you need the 64-bit version of one of these Ubuntu versions:

  • Eoan 19.10
  • Bionic 18.04 (LTS)
  • Xenial 16.04 (LTS)

Docker Engine — Community is supported on x86_64 (or amd64), armhf, arm64, s390x (IBM Z), and ppc64le (IBM Power) architectures.

You will get all the information related to installing Docker to your machine using this link.

Uninstall old versions

Older versions of Docker were called docker, docker.io, or docker-engine. If these are installed, uninstall them:

$ sudo apt-get remove docker docker-engine docker.io containerd runc

It’s OK if apt-get reports that none of these packages are installed.

The contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved. The Docker Engine - Community package is now called docker-ce.

Install Docker

Before you install Docker Engine — Community for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.

  1. Update the apt package index:
$ sudo apt-get update

2. Install packages to allow apt to use a repository over HTTPS:

$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common

3. Add Docker’s official GPG key:

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

Verify that you now have the key with the fingerprint by searching for the last 8 characters of the fingerprint.

$ sudo apt-key fingerprint 0EBFCD88

4. Use the following command to set up a stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below.

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

Note: The lsb_release -cs sub-command below returns the name of your Ubuntu distribution, such as xenial. Sometimes, in a distribution like Linux Mint, you might need to change $(lsb_release -cs) to your parent Ubuntu distribution. For example, if you are using Linux Mint Tessa, you could use bionic. Docker does not offer any guarantees on untested and unsupported Ubuntu distributions.

INSTALL DOCKER ENGINE — COMMUNITY

First, we will use this command to update the apt package index.

$ sudo apt-get update

Then install the latest version of Docker Engine — Community and containerd, or go to the next step to install a specific version:

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

If you have multiple Docker repositories enabled, installing or updating without specifying a version in the apt-get install or apt-get update command always installs the highest possible version, which may not be appropriate for your stability needs.

To install a specific version of Docker Engine — Community, list the available versions in the repo, then select and install:

Use this command to list the versions available in your repo:

$ apt-cache madison docker-ce

To check Docker version type this command

$ sudo docker version

4. Verify that Docker Engine — Community is installed correctly by running the hello-world image.

$ sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

UPGRADE DOCKER ENGINE — COMMUNITY

To upgrade Docker Engine — Community, first, run sudo apt-get update, then follow the installation instructions, choosing the new version you want to install.

Now Docker is successfully installed to your system.

Start Docker

To start Docker use this command

$ sudo service docker start

Now run the command $ sudo docker info and you will get all the information about the Docker running in your system.

You can add your user to the Docker group (Optional). For example my user is userEx and run this command

$ sudo usermod -a -G docker userEx

Now you can run some Docker commands.

$ sudo docker images

This will list all the images.

$ sudo docker ps -a

This will list all running containers.

As mentioned above to run the image you can type the command

$ sudo docker run <image name>

If the images are not present on your system ideally Docker should get this image from Docker Hub which is an online Docker repository and then run the image and start the container.

Stop Docker

You can use the below command to stop Docker.

$ sudo service stop docker 

Uninstall Docker

You can use this command to uninstall Docker from your machine.

$ sudo apt-get remove docker docker-engine docker.io containerd runc

Helpful Tips

You can visit https://get.docker.com/ for more installation-related help.

To install Docker from binaries https://docs.docker.com/install/linux/docker-ce/binaries/

Thank You!

Next Article

--

--

Kasun Dissanayake

Senior Software Engineer at IFS R & D International || Former Software Engineer at Pearson Lanka || Former Associate Software Engineer at hSenid Mobile