In my last article I shared the steps to configure or build ceph storage cluster in Openstack. Now in this article I will share the steps to install docker on CentOS 7 or RHEL 7 Linux and to configure thin provisioning storage for Docker, Now Docker is one of the most common container solution, but it's not the only container solution.
- Docker
- Kubernetes, which is based on Google technology.
- Mesos, that is coming from the Apache Foundation.
Let us understand some more about these container solution
What is Docker?
- Well, in Docker all applications and dependencies are packaged in one single binary, which is the container.
- The way how you work with Docker closely resembles to GIT. You use
docker push
,docker pull
,docker commit
which closely looks like GIT commands that you are using to download something from GIT, to work with it, to upload something to GIT, and to commit changes if you want to. - The core of Docker is Docker image. Docker images are built upon immutable file system images.
Docker hub
,Docker registry
, andDocker datacenter
can be used for image storage - Image storage is very important in the Docker environment. And the way how you want to deal with it really depends on the level of scalability that is required in your environments. The easiest solution is to use
Docker hub
, which is all online. But if you need to run a lot of containers within your own datacenter, you can useDocker datacenter
instead. - If you are running multiple containers and as your business starts to depend more and more on containers, you may need to implement Orchestration also. This happens by using external and often third-party solutions such as
Marathon
,SWARM
,Kubernetes
, andOpenShift
. - Docker itself is a commercial solution that is offered by Docker, Inc. Recently, an open-source development version has been split off and made available through the Moby project.
What is Kubernetes?
- Kubernetes was designed from scratch with Google Borg as the leading example and open-sourced in 2015
- It is based on the Docker container image and it's managed by CNCF instead of a single company.
- Kubernetes container technology is independent of the underlying infrastructure and it offers a standard deployment interface regardless of the cloud vendor that is using it.
- it has powerful tools for developers.
What is Mesos container technology?
- Mesos was designed as a next generation cluster-manager.
- It offers datacenter resources abstraction, which makes it cloud agnostic.
- It also allows you to do colocation of different workloads. That means that you can run containerized and non-containerized workloads within the same environment.
- Automates operations like deployment, self-healing, and scaling.
- Providing High Availability fault-tolerant environment.
- It provides exstensibility and it allows you to elastically scale.
Before we start with the steps to install Docker on CentOS 7, we need to know a little bit about Docker terminology; otherwise, you will be so confused about the different components that you'll be working with.
- Container Image: It's a full image that consists of multiple, read-only layers and only one writeable layer.
- Base Image: The base image is a fresh operating system without additional layers, so it's the lowest layer in the imaging in the Docker container image.
- Image Layer: Each change to the base layer will result in a new layer that is stacked on the currently existing layers.
- Container: A running instance of a container image
- Docker Host: The host where the Docker containers are running
- Docker Hub: The central Docker repository, that contains many ready-to-use container images.
Pre-requsites to Install Docker on CentOS 7
- 8 GB of RAM
- 50 GB of Storage for container images
- Optional storage for persistent volumes
Perform clean up
It is important that before starting with a fresh installation first you must make sure that there are no old versions available any more.
# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
Install Docker on CentOS 7
Once the old docker content has been removed, we can continue to install Docker on CentOS 7. That starts with some dependencies:
yum
can install the provided rpm and it's dependencies.[root@node1 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
Next, we need to add a repository to install docker on CentOS 7. We can do add a repo using yum-config-manager
. Here CE stands for Community Edition. That is to distinguish between the free Community Edition
and the Enterprise Edition
that requires separate licensing.
[root@node1 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
Next to install docker on CentOS 7 Linux we need to run yum install docker-ce
to actually install it
# yum install docker-ce
Now that the software has been installed, we can use systemctl enable docker
to enable the Docker service.
[root@node1 ~]# systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
As you see the status of docker service, it is showing that it is currently enabled
, but not running
; it's marked as dead
.
[root@node1 ~]# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: inactive (dead) Docs: https://docs.docker.com
So systemctl start docker
is going to start the Docker backend service that is taking care of all of these containers.
[root@node1 ~]# systemctl start docker
Setup LVM Thin Provisioning
Next we need to take care of storage. In order to do so, we are going to create an LVM storage pool for the container images; and we will be using device mapper direct lvm.
Now we need a block device in this container storage. We need to create an LVM storage pool for the container images; and in order to so, we are using device mapper direct LVM.
[root@node1 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <9.52g 0 /dev/sdb1 centos lvm2 a-- <8.00g 1020.00m
To check the list of available partitions and devices on your system. As we see we have /dev/sdc
as a free partition and is not used by our LVM. So we can use /dev/sdc
as a physical volume.
[root@node1 ~]# ls -l /dev/sd*
brw-rw---- 1 root disk 8, 0 Dec 20 15:40 /dev/sda
brw-rw---- 1 root disk 8, 1 Dec 20 15:40 /dev/sda1
brw-rw---- 1 root disk 8, 2 Dec 20 15:40 /dev/sda2
brw-rw---- 1 root disk 8, 16 Dec 20 15:40 /dev/sdb
brw-rw---- 1 root disk 8, 17 Dec 20 15:40 /dev/sdb1
brw-rw---- 1 root disk 8, 32 Dec 20 15:40 /dev/sdc
We will create physical volume using pvcreate
for /dev/sdc
[root@node1 ~]# pvcreate /dev/sdc Physical volume "/dev/sdc" successfully created.
Next create a volume group using the physical volume on /dev/sdc
[root@node1 ~]# vgcreate vg_docker /dev/sdc
Volume group "vg_docker" successfully created
Next create a logical volume with name "thinpool
". We create it under vg_docker
volume group, and we allocate a size of 95%
of the volume group.
[root@node1 ~]# lvcreate --wipesignatures y -n thinpool vg_docker -l 95%VG
Logical volume "thinpool" created.
We also want to create an LVM volume with the name thinpoolmeta
, which is used for the metadata.
[root@node1 ~]# lvcreate --wipesignatures y -n thinpoolmeta vg_docker -l 1%VG
Logical volume "thinpoolmeta" created.
The reason we are separating this is so that we can allow for more efficient storage once we get to the Docker environment.
Next we change the logical volume layout using lvconvert
, this is going to setup your thin storage pool, and a thin pool is exactly what you need to make the storage of the docker images as efficient as possible
[root@node1 ~]# lvconvert -y --zero n -c 512K --thinpool vg_docker/thinpool --poolmetadata vg_docker/thinpoolmeta Thin pool volume with chunk size 512.00 KiB can address at most 126.50 TiB of data. WARNING: Converting vg_docker/thinpool and vg_docker/thinpoolmeta to thin pool's data and metadata volumes with metadata wiping. THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.) Converted vg_docker/thinpool and vg_docker/thinpoolmeta to thin pool.
Here -y -> Do not prompt for confirmation interactively but always assume the answer yes --zero -> For snapshots, this controls zeroing of the first 4KiB of data in the snapshot. If the LV is read-only, the snapshot will not be zeroed. For thin pools, this controls zeroing of provisioned blocks. Provisioning of large zeroed chunks negatively impacts performance. -c -> The size of chunks in a snapshot, cache pool or thin pool --thinpool -> The name of a thin pool LV.
Next we are going to create configuration file, and we choose the name vg_docker_image.profile
[root@node1 ~]# cat /etc/lvm/profile/vg_docker_image.profile
activation {
thin_pool_autoextend_threshold=80
thin_pool_autoextend_percent=20
}
These are the parameters that in the thin port storage pool will be used for automatically extending the thin storage.
Now we need to use vim to create the profile file.
You should make sure that this matches the name of the thinpool that you have created
[root@node1 ~]# cat /etc/lvm/profile/vg_docker-thinpool.profile
activation {
thin_pool_autoextend_threshold=80
thin_pool_autoextend_percent=20
}
Now that we have created the profile for the thinpool that we are going to create, we can convert the LVM volume to a thin provisioned LVM volume
[root@node1 ~]# lvchange --metadataprofile vg_docker-thinpool vg_docker/thinpool Logical volume vg_docker/thinpool changed.
[root@node1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <15.78g
swap centos -wi-ao---- 760.00m
thinpool vg_docker twi-a-t--- 7.59g 0.00 0.05
And there we can see that the logical volume has just changed. Now we need to create a Docker configuration file "daemon.json
"
[root@node1 ~]# cat /etc/docker/daemon.json { "storage-driver": "devicemapper", "storage-opts": [ "dm.thinpooldev=/dev/mapper/vg_docker-thinpool", "dm.use_deferred_removal=true", "dm.use_deferred_deletion=true" ] }
- So the storage driver is set to
devicemapper
, which tells Docker that it should use the device mapper storage layer. - The storage options are specified as
dm.thinpooldevice
, which is thethinpool
that it should be using; - And then we have the
dm.use_deferred_removal=true
anddm.use_deferred_deletion=true
that need to be included in there as well.
With this we are done with the steps to install docker on CentOS 7 Linux, now it's a smart idea to restart docker. We have previously started it, but in the previous start it wasn't using this thin provisioning.
[root@node1 ~]# systemctl restart docker
And now we can see that the Docker daemon is active and running.
[root@node1 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2018-12-20 15:51:20 IST; 57min ago
Docs: https://docs.docker.com
Main PID: 2601 (dockerd)
Tasks: 8
Memory: 33.1M
CGroup: /system.slice/docker.service
└─2601 /usr/bin/dockerd -H unix://
Dec 20 15:51:20 node1.example.com dockerd[2601]: time="2018-12-20T15:51:20.567366488+05:30" level=info msg="Succ...pper
Dec 20 15:51:20 node1.example.com dockerd[2601]: time="2018-12-20T15:51:20.599102217+05:30" level=info msg="Grap...nds"
Dec 20 15:51:20 node1.example.com dockerd[2601]: time="2018-12-20T15:51:20.599562425+05:30" level=info msg="Load...rt."
Hint: Some lines were ellipsized, use -l to show in full.
Lastly I hope the steps from the article to install docker on CentOS 7 Linux was helpful. So, let me know your suggestions and feedback using the comment section. In my next article I will share Tutorial: How to manage docker container with examples ?
Your mode of explaining all in this piece of writing is in fact
good, every one be capable of effortlessly be aware
of it, Thanks a lot.
Hi there! Such a good short article, thank you!