Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again.
Thanks!

Docker Basics and Install

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:

Code:

sudo apt remove docker docker-engine docker.io

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:

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’.

Code:

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:

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:

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

Code:

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:

Code:

sudo systemctl start docker

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

Code:

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:

Code:

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:

Code:

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’.

(Log in to hide this advertisement)

The output should look similar to Figure 1.

FIGURE 01

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:

Code:

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:

Code:

apt update
apt install htop
htop

A window should appear similar to Figure 2.

FIGURE 02

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

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.

I work at home and I have an extremely beautiful wife named Cassandra. We've been married nearly 25 years. We have four children at home: Eilly, Alyse, Morgan and Grant.

I tried it out and happy to say that it works. I followed the number 15 reply in the document below. The script build-image.sh works well. When you install docker images after installing docker, make sure you download images of 32-bit architecture. Otherwise, it will not work.

Our other sites!

Membership Upgrade

The management works very hard to make sure the community is running the best software, best designs, and all the other bells and whistles. Support the site by purchasing a membership upgrade. We'd really appreciate it!