Docker : Rubrik Central - Docker Edition!
Background
After publishing my post about Rubrik Central months ago, I have received comments saying that it is too difficult to deploy and has too many pre-requisites. I thought about automating the deployment process in many ways and found that containers could be a nice option. But I didn't know anything about Docker. So, I did some research and I think I came across with something definitely usable !
What is Docker ?!?
Docker is the next step to virtualization. Virtualization is actually the same as a bare metal/physical server, the hardware set aside. Containers do not come with a full OS, this is only a baseline that allows you to run apps. Anything can be converted into a container and containers can be create and destroyed on the go very quickly.
If you are not interested by all the technical details, please scroll down to the Installation section.
What do I need to run Rubrik Central ?
Basically very few things ...
- A web server
- Php
- Couple of files
- Configuration file
Very easy. So, let's create a container with these basic features.
Dockerfile
A Dockerfile is a list of instructions that will be executed during the build process. The build process is creating the container itself from an existing base image. The machine where you are deploying the container MUST have access to the Internet in order to download the container baseline.
$ cat Dockerfile
FROM centos:7
# Install latest updates
RUN yum -y update
# Install Apache
RUN yum -y install httpd httpd-tools
# Install EPEL Repo
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# Install PHP
RUN yum -y install php72w php72w-bcmath php72w-cli php72w-common php72w-gd php72w-intl php72w-ldap php72w-mbstring php72w-mysql php72w-pear php72w-soap php72w-xml php72w-xmlrpc
# Update Apache Configuration
RUN sed -E -i -e '/<Directory "\/var\/www\/html">/,/<\/Directory>/s/AllowOverride None/AllowOverride All/' /etc/httpd/conf/httpd.conf
RUN sed -E -i -e 's/DirectoryIndex (.*)$/DirectoryIndex index.php \1/g' /etc/httpd/conf/httpd.conf
RUN sed -i "s,/var/www/html,/var/www/html/rubrik,g" /etc/httpd/conf/httpd.conf
# Open port 80 for local www browsing
EXPOSE 80
# Extra data files to container
ADD RubrikCentral.tgz /
# Start Apache
CMD ["/usr/sbin/httpd","-D","FOREGROUND"]
In a nutshell, this will :
- create an image based on CentOS 7;
- update all packages;
- install apache;
- install php;
- modify the apache config to enable php execution;
- open port 80;
- extract the Rubrik Central php files;
- start apache
Next, we need to build our container :
$ cat build.sh
#!/bin/bash
# Generate archive to import files into container
tar -czfv ./RubrikCentral.tgz /var/www/html/rubrik/* 2>/dev/null
# Generate container image
sudo docker build -t image_rubrik_central .
Output :
$ ./build.sh
Sending build context to Docker daemon 441.9 kB
Step 1/11 : FROM centos:7
---> 8652b9f0cb4c
Step 2/11 : RUN yum -y update
---> Using cache
---> b3bbb1ebe478
Step 3/11 : RUN yum -y install httpd httpd-tools
---> Using cache
---> b7464be9f27b
Step 4/11 : RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
---> Using cache
---> 446af266fa52
Step 5/11 : RUN yum -y install php72w php72w-bcmath php72w-cli php72w-common php72w-gd php72w-intl php72w-ldap php72w-mbstring php72w-mysql php72w-pear php72w-soap php72w-xml php72w-xmlrpc
---> Using cache
---> 6c7354217c10
Step 6/11 : RUN sed -E -i -e '/<Directory "\/var\/www\/html">/,/<\/Directory>/s/AllowOverride None/AllowOverride All/' /etc/httpd/conf/httpd.conf
---> Using cache
---> bfbbea237450
Step 7/11 : RUN sed -E -i -e 's/DirectoryIndex (.*)$/DirectoryIndex index.php \1/g' /etc/httpd/conf/httpd.conf
---> Using cache
---> 5afa38de8bd1
Step 8/11 : RUN sed -i "s,/var/www/html,/var/www/html/rubrik,g" /etc/httpd/conf/httpd.conf
---> Using cache
---> a4cc1efaab77
Step 9/11 : EXPOSE 80
---> Using cache
---> 28877ed18f70
Step 10/11 : ADD RubrikCentral.tgz /
---> Using cache
---> e9b5797dd2d9
Step 11/11 : CMD /usr/sbin/httpd -D FOREGROUND
---> Running in 7895db60fc67
---> 34a5ec2749d5
Removing intermediate container 7895db60fc67
Successfully built 34a5ec2749d5
We now have a new image ready to be used :
$ sudo docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
image_rubrik_central latest 34a5ec2749d5 6 minutes ago 733 MB
Next step is to start the container. But, there is a trick. Remember, we have exposed port 80 in the Dockerfile to have port 80 available when accessing the web server inside the container. But, sometimes, you probably want to have another port without re-creating the entire container image and start a new build process. So, you can create a port mapping when starting up the container with a specific instruction. This is what we are going to do : we would like to map the OS port 8080 to the container port 80. This can be done this way :
$ sudo docker run -tid -p 8080:80 --name=RubrikCentral image_rubrik_central
dd344d5ef426870be44234ec6c96df2b5a92f45d0ed5634e3d3212e76fd8f878
To confirm the container is running :
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd344d5ef426 image_rubrik_central "/usr/sbin/httpd -..." 53 seconds ago Up 51 seconds 0.0.0.0:8080->80/tcp RubrikCentral
We see the port redirection in this status screen. This way, we can have port 80 on the OS running to an existing www server and 8080 exposed to our container internal port. Both can work together. Even more than that, I can have a first container on port 8080 and another one on port 8088 for example.
Now, let's open a browser to http://<host_ip>:8080/. Once configured, you should be able to see something like this :
It works perfectly ! (note the port in the address bar).
$ netstat -teln | grep 8080
tcp6 0 0 :::8080 :::* LISTEN 0 499202451
Now, to stop the container, we can run the following command :
$ sudo docker kill dd344d5ef426
dd344d5ef426
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
If we start again the container with the same command as above it will failed. Indeed, the container name already exists. If the container is stopped, his image still exists in the Docker library.
$ sudo docker run -tid -p 8080:80 --name=RubrikCentral image_rubrik_central
/usr/bin/docker-current: Error response from daemon: Conflict. The container name "/RubrikCentral" is already in use by container 284669416b526660a14e9a849c7ac91012a2504676e3e35fc5e399e1f78d314b. You have to remove (or rename) that container to be able to reuse that name..
See '/usr/bin/docker-current run --help'.
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
284669416b52 image_rubrik_central "/usr/sbin/httpd -..." 44 seconds ago Exited (137) 17 seconds ago RubrikCentral
We have 2 options to solve this issue :
- Change the container name to something else;
- Delete the existing entry in the Docker library
To change the name easy : put something else in the --name statement of the docker run command.
To delete the existing entry in the Docker library use this command :
$ sudo docker rm RubrikCentral
RubrikCentral
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Entry is gone and the name can be reused.
Note : you have noticed that I'm using sudo in front of each docker commands. This can be changed following this procedure. But, I prefer to keep this habit, so I know what I'm doing when typing sudo.
Installation
At this stage, we have seen how it works under the hood, this is now time to deploy it ! I have created a GitHub repo here, feel free to grab the tar file. There are some scripts to assist you with the deployment. So, even if you totally skipped the above section, you are still good to go.
1) Extract the files
$ tar xvfz ../RubrikCentralContainer.tgz
Dockerfile
install.sh
RubrikCentral.tgz
start.sh
status.sh
stop.sh
2) Run installer
$ ./install.sh
###################################################
# Welcome to Rubrik Central - Docker Edition #
###################################################
This Script requires *Docker* to be installed.
Checking is Docker is installed ...
Docker found (Docker version 1.13.1, build 0be3e21/1.13.1). Continuing!
Creating Docker image...
Sending build context to Docker daemon 4.366 MB
Step 1/11 : FROM centos:7
---> 8652b9f0cb4c
Step 2/11 : RUN yum -y update
---> Using cache
---> b3bbb1ebe478
Step 3/11 : RUN yum -y install httpd httpd-tools
---> Using cache
---> b7464be9f27b
Step 4/11 : RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
---> Using cache
---> 446af266fa52
Step 5/11 : RUN yum -y install php72w php72w-bcmath php72w-cli php72w-common php72w-gd php72w-intl php72w-ldap php72w-mbstring php72w-mysql php72w-pear php72w-soap php72w-xml php72w-xmlrpc
---> Using cache
---> 6c7354217c10
Step 6/11 : RUN sed -E -i -e '/<Directory "\/var\/www\/html">/,/<\/Directory>/s/AllowOverride None/AllowOverride All/' /etc/httpd/conf/httpd.conf
---> Using cache
---> bfbbea237450
Step 7/11 : RUN sed -E -i -e 's/DirectoryIndex (.*)$/DirectoryIndex index.php \1/g' /etc/httpd/conf/httpd.conf
---> Using cache
---> 5afa38de8bd1
Step 8/11 : RUN sed -i "s,/var/www/html,/var/www/html/rubrik,g" /etc/httpd/conf/httpd.conf
---> Using cache
---> a4cc1efaab77
Step 9/11 : EXPOSE 80
---> Using cache
---> 28877ed18f70
Step 10/11 : ADD RubrikCentral.tgz /
---> Using cache
---> b61d1a6e6539
Step 11/11 : CMD /usr/sbin/httpd -D FOREGROUND
---> Using cache
---> 57a474e0046e
Successfully built 57a474e0046e
Enter TCP port for web server : 8080
f32c0768aa8018221f79d432ad2db6164edca34133e31848ac790f867a513c28
Container is running
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f32c0768aa80 image_rubrik_central "/usr/sbin/httpd -..." Less than a second ago Up Less than a second 0.0.0.0:8080->80/tcp myRubrikCentral
You can open a browser on the following URL : http://<localhost>:8080
If you see the last line asking you to open an URL with the tcp port you have selected, this is a good sign !
3) Open a browser to the URL given by the script :
Since this is the first start of the site, there is no configuration ready, you need to create one, click on the Configure now! button to reach the configuration screen ;
In this screen, you need to enter the clusters details. Minimum one and maximum 5. I've noticed that starting at 5 clusters and above the performance are decreasing drastically. So, for now, the application is limited to 5 clusters.
When you have entered the details, click on Save.
It will then guide you to the main screen :
If you need to add other cluster or modify the existing one, click on the gear icon, top right.
This configuration screen is new compared to the original release of Rubrik Central. It easier, I think, to managed the configuration this way rather than editing a php file for populating an array.
Closing words
There are some additional scripts in the folder where you have extracted the tar file :
./status.sh shows the actual status of the container :
$ ./status.sh
Container Status :
f32c0768aa80 image_rubrik_central "/usr/sbin/httpd -..." About an hour ago Up About an hour 0.0.0.0:8080->80/tcp myRubrikCentral
./stop.sh is stopping the container but still keep it :
$ ./stop.sh
Stoping container ....
myRubrikCentral
Done.
./start.sh is restarting a previously stopped container :
$ ./start.sh
Starting container ....
myRubrikCentral
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f32c0768aa80 image_rubrik_central "/usr/sbin/httpd -..." About an hour ago Up Less than a second 0.0.0.0:8080->80/tcp myRubrikCentral
./cleanup.sh is stopping the container and removing it from the disk. The only way to restart it is to use ./install.sh and start from scratch : all configuration is lost :
$ ./cleanup.sh
Cleaning up ....
myRubrikCentral
Done.
I hope you enjoy this post, covering both a new way to deploy applications and the enhancements I've added into Rubrik Central.
;)
Cool. Have a look at portainer
ReplyDeleteLooks interesting !!!! Thanks for sharing Geert.
Delete