How to Install & Configure Docker in Centos/RHEL 6

Install & Configure Docker in Centos/RHEL 6


What is Docker?


Docker is all about making it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

In a way, Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they're running on and only requires applications be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application.



And importantly, Docker is open source. This means that anyone can contribute to Docker and extend it to meet their own needs if they need additional features that aren't available out of the box.



Requirements:-


1. Centos/RHEL 6.X
2. 2 GB RAM (Recommanded)
3. 50 GB HDD
4. Virtual IP on a Virtual NIC (** For production the Virtual IP Will be a Public IP)

** Here the Virtual IP is: 10.100.100.118 & the Virtual NIC is eth0:1

Step 1: Stop the Selinux, and Update the Date Time on the Server :



# vi /etc/sysconfig/selinux

SELINUX=disabled ###(Change enabled to disabled)

--- save & quit (:wq) ---

# service ntpd restart
# ntpdate pool.ntp.org
# chkconfig ntpd on

Step 2: Install & Configure Docker :



# yum -y install epel-release
# yum -y update
# yum -y install docker-io
# service docker start
# chkconfig docker on
# service iptables save

Note: ** Now the IPTales will save with all the Rules & Chains will save to the IPTables Main File.



Step 3: Download Images and Configure Docker Container :



Note: ** What kind of OS need that can be find by the Docker Search, Here using the centos6.6 Image for Example, For find a Image with the Version Run the Below Command-



# docker search <OS> (i.e., # docker search ubuntu)

** We are doing with Centos 6.6-
** To download an Image Run the Below Command

# docker pull centos:6.6

** To see the Downloaded Image Run the Below Command

# docker images

** To create a Docker Instance With a Dedicated IP and with the Port Binding for Accessing the VMs from Outside Do the Following things



# cd /etc/sysconfig/network-scripts/
# cp ifcfg-eth0 ifcfg-eth0:1
# vi ifcfg-eth0:1

### Delete All Lines and Add these Lines

DEVICE=eth0:1
TYPE=Ethernet
UUID=0c1b31b3-bcde-4a28-b2b0-581d3f01e33a
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=10.100.100.118
NETMASK=255.255.0.0
GATEWAY=10.100.1.1

---- save & quit (:wq) ----

# ifup eth0:1

** If the NIC doesn't comes up then Run the Below Command-



# service network restart

# ifconfig

** Check the NIC's once that every NIC is up.



** Now Create a Docker Container with the IP 10.100.100.118 with Port Bind to Host Port 5000 to Container's 22 Port-



# docker run -i -t -p <IP>:<Host Port>:<Container's Port> --privileged --name <Any Name> <Image name> <Command> ## --privileged is for run the container with a Root Privileges

# docker run -i -t -p 10.100.100.118:5000:22 --privileged --name NEWVM centos:6.6 /bin/bash

** After run this Command you will Enter into the Container



[root@df4b1cb88bd8 /]# yum -y install openssh*
[root@df4b1cb88bd8 /]# vi /etc/ssh/sshd_config

## Uncomment the Line at Line Number 42
PermitRootLogin yes

---- save & quit (:wq) ----

# service sshd restart
# chkconfig sshd on

** Set root Password; for here its Passw0rd



# passwd root
# netstat -tulpn |grep 22

** To check that the SSH port is Running and Open.



** Now connect the Container from Outside by the IP: 10.100.100.118 Port: 5000 User: root Pass: Passw0rd



Step 4: Set the Httpd for the Created Container with the Virtual IP with 8080 Port :



# service iptables save
# docker stop NEWVM
# docker commit NEWVM newimage02
# docker run -i -t -p 10.100.100.118:5000:22 -p 10.100.100.118:8080:80 --privileged --name NEWVM newimage02 /bin/bash

[root@df4b1cb88bd8 /]# service sshd restart
[root@df4b1cb88bd8 /]# exit

# service iptables save

** Connect the VM through SSH from Outside by the IP: 10.100.100.118 Port: 5000 User: root Pass: Passw0rd



[root@df4b1cb88bd8 /]# yum -y install httpd httpd-devel
[root@df4b1cb88bd8 /]# service httpd restart
[root@df4b1cb88bd8 /]# chkconfig httpd on

** Now check on Brwoser Apache Default Page Will come:



http://10.100.100.118:8080

Step 5: Set the MySLQ for the Created Container with the Virtual IP with 3030 Port :



# service iptables save
# docker stop NEWVM
# docker commit NEWVM newimage01
# docker rm NEWVM
# docker run -i -t -p 10.100.100.118:5000:22 -p 10.100.100.118:3030:3306 --privileged --name NEWVM newimage01 /bin/bash

[root@df4b1cb88bd8 /]# service sshd restart
[root@df4b1cb88bd8 /]# exit

# service iptables save

** Connect the VM through SSH from Outside by the IP: 10.100.100.118 Port: 5000 User: root Pass: Passw0rd



[root@df4b1cb88bd8 /]# yum -y install mysql-server mysql-devel
[root@df4b1cb88bd8 /]# service mysqld restart
[root@df4b1cb88bd8 /]# chkconfig mysqld on
[root@df4b1cb88bd8 /]# mysql_secure_installation

Step 6: Some Special Notes:-



** After Restarting the Docker Container/Main Server if the SSH not working with the Virtual/Public IP the have to login into the Docker and Restart the SSH once.



** To check the Docker Containers Lists-



# docker ps -a

# docker exec -it <Container Name> /bin/bash
[root@df4b1cb88bd8 /]# service sshd restart
[root@df4b1cb88bd8 /]# service httpd restart

Then check the SSH & Http Connections Again

** To take Backup of a Container or Create an Image from a Container Run the Following Command:-



# docker commit <Container Name/ID> <New Image Name>
# docker commit NEWVM image01

** To Check the Ports that Which Host Port Assign to Which Container's Port Run the Following Command:-



# docker port <Container Name/ID>
# docker port NEWVM


*** If Need to Open more that the Existing port for the Container then do the Following Things:-



# docker stop <Container Name/ID>
# docker commit <Container Name/ID> <New Image Name>
# docker rm <Container Name/ID>
# docker run -i -t -p <Virtual IP>:<Physical Host>:<Container's Port> -p <Virtual IP>:<Physical Host>:<Container's Port> -p <Virtual IP>:<Physical Host>:<Container's Port> --privileged --name <New Container Name> <The Saved Image Name> /bin/bash

** Then Check the Container As Previously Described



Thanks For Visiting on My Blog, For More Tutorials Keep Visiting My Blog.

1 comments:

"No package docker-io available."