Docker is a container virtualization technology that has gained widespread popularity in recent times, it offers more efficient way to deploy the application. With Docker, the applications resides inside the container on top of the Linux operating system. Docker uses Kernel features such as cgroups and namespace to allow independent container to run on single os instance.
In this post, you will learn how to install Docker on CentOS 7 / RHEL 7 / Fedora 21
Note: Docker runs only on 64 bit operating system.
Installing Docker:
Docker package:
docker.x86_64 0:1.8.2-10.el7.centos
Docker Dependencies:
device-mapper.x86_64 7:1.02.107-5.el7
device-mapper-event.x86_64 7:1.02.107-5.el7
device-mapper-event-libs.x86_64 7:1.02.107-5.el7
device-mapper-libs.x86_64 7:1.02.107-5.el7
device-mapper-persistent-data.x86_64 0:0.5.5-1.el7
docker-selinux.x86_64 0:1.8.2-10.el7.centos
lvm2.x86_64 7:2.02.130-5.el7
lvm2-libs.x86_64 7:2.02.130-5.el7
Docker is available in standard repository of CentOS, so we don’t have to search for package. For RHEL 7, you must have a valid Redhat subscription to enable Extras rpm’s respository on server. Install it using the following command.
# yum -y install docker device-mapper device-mapper-event device-mapper-event-libs device-mapper-libs device-mapper-persistent-data docker-selinux lvm2 lvm2-libs
Now you have Docker installed onto your machine, start the Docker service incase if it not started automatically after the installation
# systemctl start docker.service # systemctl enable docker.service
Once the service is started, verify your installation by running the following command.
# docker run -it centos echo Hello-World
Lets see what happens when we run “docker run” command. Docker starts a container with centos base image, since we are running this centos container for first time, the output will look like below.
Unable to find image 'centos:latest' locally
Trying to pull repository docker.io/centos ...
0114405f9ff1: Download complete
511136ea3c5a: Download complete
b6718650e87e: Download complete
3d3c8202a574: Download complete
Status: Downloaded newer image for docker.io/centos:latest
Hello-World
Docker looks for centos image locally, and it is not found, it starts downloading the centos image from docker registry. Once the images has been downloaded, it will start the container and echo the command “Hello-World” in the console which you can see at the end of the output.
Allowing Non-root access:
As you can see in my command, for CentOS i had to run docker as root user. To avoid this you can follow below procedure to allow non-root users to run Docker containers.
Create a group called docker, run the following commands with root privileges.
# groupadd docker
Add a user that is to be a part of docker group, replace “sam” with your own user name.
# useradd sam
Add a user to docker group.
# usermod -aG docker sam
Now you can run a Docker with non-root user.
FirewallD:
FirwallD in CentOS 7 can conflict with Docker, it is recommended to disable the service.
# systemctl stop firewalld.service # systemctl disable firewalld.servic
When firewalld is started or restarted it will remove the DOCKER chain from iptables, it prevents Docker from working properly.
If you still want to use Systemd, firewalld is must be started before Docker service. In case if you start or restart firewalld after Docker, you will have to restart the Docker daemon.
That’s All!, You can now start working with Docker.
No comments:
Post a Comment