Coding, Web, Hydrology and more.

The Installation and Configuration of Docker in CentOS

T

0x00 What’s Docker?

Docker is an open-source app container engine, which allows developers pack their app and dependencies into a portable container, then the developers could deploy it on any machines based on Linux. Moreover, it could also be used for virtualization, where every container is isolated from each other by sandbox mechanism.

0x01 How to install Docker?

Before installation, you need to be aware of some prerequisites of Docker.

Firstly, it is highly recommended to install Docker on CentOS 7 or higher, but Docker could also be installed on CentOS 6.x if you insist. Link

Secondly, the old version of Docker should be removed before the new version is installed, which can be done using the instructions given below.

If all these prerequisites are obtained, the next thing to do is installing Docker.

As a matter of fact, there are various ways for us to install Docker. Here I want to recommend a simple and easy way to install Docker, that is, setting up Docker’s repositories and installing from them.

The first thing we need to do is to set up Docker’s repositories.

There are three required packages we need to install, they are yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data and lvm2 are required by the devicemapper storage driver.

While choosing which version to be installed, we are told that there are three kinds of version for us to choose, they are stable, test, edge. For me I would recommend you the stable version, therefore the following instructions will show you how to set up a stable repository, what’s more, setting up a stable repository is inevitable on condition that you’d like to install a test or edge version.

After saving the repository, we are able to install the Docker now.

If it is the first time you install Docker, you are prompted to accept the GPG key, and the key’s fingerprint is shown.

Verify that the fingerprint is correct, and if so, accept the key.

The fingerprint should match 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35.

Well then the docker is successfully installed, but we should know that we are just half-way to success.

In next step, we are going to start the docker and configure it for a better performance.

After typing this instruction, your docker will start on condition that you follow the steps.

Now that we install docker, we probably want it start on boot, there are various way to do it, for this purpose I use systemd

Attention should be paid to the default storage engine, the default storage engine Docker uses is Overlay2, however, the recommended storage engine is devicemapper on CentOS, so if you encounter Error response from daemon: mkdir xxxx: invalid argument, you should change your storage engine to devicemapper by editing /etc/docker/daemon.json(if it is not existed, create one) and typing following code:

and then restart docker, it probably will fix that issue.

In addition, when you are using xfs or ext4 file system in CentOS, you will probably see a warning when you type $ docker info like this

WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.

That means that the default setting of devicemapper is using loopback to generate storage pool which is highly discouraged because it is really unstable and slow.

If you use LVM, the problem can be easily fixed,

Append this code to daemon.json after storage-driver part:

From now on you have installed a very pure but extensible Docker on your machine, the truth is, you can change more specific configurations of Docker, such as choosing the storage engine, enabling ipv6 and setting DNS server etc.

For detailed information, check Docker Documentation: https://docs.docker.com/

0x02 What to do with Docker?

The first time I saw Docker, I believe that it is a container of all potential. AFAIK, you can use Docker to set up identical application in a variety of container which have difference version of dependencies working in them, you can separate different applications to stop a jail-break influence of application on the mother machine or other applications, which enhances the security and ease the load of management. Therew are more features waiting for you to explore, enjoy.

About the author

EDLinus

[stay(d) for d in ('determined','diligent','devoted')]

 
By EDLinus
Coding, Web, Hydrology and more.

Meta