Docker Basics and Install

Jarret B

Well-Known Member
Staff member
May 22, 2017
Reaction score
Docker is a utility which allows a special type of virtualization. Docker allows for a program to be run “virtually” on a system by using a Docker image.
An image can be downloaded or created which can then be run. Once the image is loaded and executed it is now a container.
A container has allocated resources set aside for the program within the container. It is possible that a container can be nearly a whole Operating System (OS) or a single application. Changes can be made within the Docker container and saved to the Docker image. Programs outside the container cannot easily interact with the programs in the container. It is possible to have containers interact with other containers.

NOTE: On the Host Operating System the Docker information is stored in ‘/var/lib/docker/’.

When a container is running there is no real overhead since the Host Linux Kernel is managing the running process. It is not like the CPU, RAM and drive space overhead when running a Virtual Machine (VM).
Let’s get Docker installed and I can show you the used resources of a container.

Ubuntu Installation

To install Docker on Ubuntu you need to be running Ubuntu 14.04, 16.04 or 18.04.
If you have installed ‘docker’ or ‘docker-engine’ previously then you need to uninstall it. To uninstall the older version of Docker perform the following:

sudo apt remove docker docker-engine

If the programs had been installed and you remove them then the files stored in ‘/var/lib/docker’ are retained.
Before installing the new ‘docker-ce’ you need to verify that your kernel version is 4.x and not 3.x. Version 3 of the Linux Kernel will work, but only supports one of the two storage drivers used by Docker.

NOTE: In a Terminal run ‘uname -r’ to find the currently running kernel version.

To set up the pre-requisites and install Docker perform the following:

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
sudo curl -fsSL | sudo apt-key add -
sudo add-apt-repository “deb [arch=amd64] $(lsb_release -cs) stable”

After the entry is added to the repository newer systems will automatically perform an update. If your system does not perform an update automatically then you need to execute the command ‘sudo apt update’.

sudo apt install docker-ce

CentOS/Fedora Installation

To install Docker on CentOS you need a 64-bit version of CentOS 7 with the centos-extras repository enabled.
To install Docker on Fedora you need a 64-bit version of Fedora 26, 27 or 28.

NOTE: There are instructions to install Docker on Fedora 29, but it is not an official installation method.

If either OS has had Docker installed then you need to remove the installation with the following command:

sudo dnf remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

If the programs had been installed and you remove them then the files stored in ‘/var/lib/docker’ are retained.
The next step is to set up the Repository for installing Docker.
In CentOS you need to perform the following commands to add the Docker Repository and install Docker:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo
sudo yum install docker-ce

For Fedora 26, 27 and 28 you need to add the Repository and install Docker by performing the following commands:

sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo
sudo dnf install docker-ce

For Fedora 29 you will need to add the repository for Fedora 28 by creating ‘/etc/yum.repos.d/docker-ce.repo’. Once created you need to add the following lines to it:

name=Docker CE Stable

Once saved you can update the repository lists and install Docker with the commands:

sudo dnf update
sudo dnf install docker-ce

For CentOS and Fedora the Docker Daemon may not be automatically started as it is in Ubuntu. To start the Docker Daemon perform the following command:

sudo systemctl start docker

To have the Docker Daemon start when the OS is booted you need to run the following command:

sudo systemctl enable docker

Finishing Up the Install

At this point only Root can execute Docker. To allow other users to run Docker then you need to add the users to the Docker Group. To create the Docker Group and add a user to the Docker Group you can perform the following:

sudo groupadd docker
sudo usermod -aG docker <username>

NOTE: On some installs the Docker Group may automatically created.

Replace ‘<username> with the login name of the users you want to add. For Ubuntu you can also use the ‘Users and Groups’ Graphical User Interface (GUI) to perform the task. If the currently logged in user is added to the group then the user needs to log out and back in for the change to take effect.

Testing Docker

At this point Docker should be installed and we can easily test this by running a command:

docker run hello-world

NOTE: If you did not add your user account to the Docker Group you will have to execute the Docker command using ‘sudo’.

The output should look similar to Figure 1.

Figure 01.jpg


Now Docker should be running on your system. If the output does not display ‘Hello from Docker!’ in the output then you need to go back and check each step.

Checking the Resources

No matter your Operating System you can run Ubuntu as a Container. The command is as follows:

docker run -it ubuntu

NOTE: The ‘-it’ parameter allows you to run the Container and allows you to interact with it.

A Terminal window should open to a Ubuntu Root prompt. Perform the following commands:

apt update
apt install htop

A window should appear similar to Figure 2.

Figure 02.jpg


You can see that the Container is only running a Bash shell and the ‘htop’ program.
In your regular OS you can install ‘htop’ if needed and then execute it. You should see something like Figure 3.

Figure 03.jpg


To exit the Docker window you need to exit the ‘htop’ program and then type ‘exit’ to leave the Container and be placed back into the normal Terminal window.
The Container is not running a ‘Full’ version of Ubuntu as you would in a Virtual Machine or Virtualbox. I hope you can see the benefits of using Containers over a complete Virtual Operating System.
You can run Docker on Windows and Mac OSX. On these Operating Systems the Docker system is emulated Linux. All calls made from the Container to the hardware must pass through a Linux Kernel. Docker will run better on a Linux system than other Operating Systems.
In future articles we can cover other systems that Docker can load and even make our own.
Last edited:

Hi Jarret,

How can I install Docker in a 32-bit Ubuntu 16.04.5 LTS system?
I am new to Linux. I wonder how you remember all the commands to install the docker between the different distributions and the many versions within each.
I have only really tried Ubuntu and Fedora. Sorry. Most of the basics should be similar though.

Members online

Latest posts