Sunday 30 April 2017

Building image with tomcat7 on Docker IO

Docker IO is evolving light weight  virtualization technology.
Take a look at Docker and play with it. This solves the problem of code shipment and makes the developer's life easy.
 Following paragraph will help you to build an image with apache installed in it. 
There are two ways to make it. 
1. Using Dockerfile  (you need to check the above link if you are surprised "Dockerfile")
2. By executing command one after another.
Though first method is simple, I will discuss the second method. 
You can do method one if you are comfortable with Docker's allowed command.

#Get a container
sudo docker run -t -i ubuntu /bin/bash

#install wget you need it
apt-get update
apt-get -f install
apt-get install wget

#Get the tomcat tar file
#if following mirror doesn't work check the page version might have changed 
wget mirror.atlanticmetro.net/apache/tomcat/tomcat-7/v7.0.54/bin/apache-tomcat-7.0.54.tar.gz
#Extract it
tar xvzf apache-tomcat-7.0.54.tar.gz
#move to the location you want 
# I move to root directory      mv apache-tomcat-7.0.54/   /tomcat7
mv apache-tomcat-7.0.54/  <any_directory>/tomcat7

#remove tar.gz
rm apache-tomcat-7.0.54.tar.gz
#Lets install java now, will come back to tomcat again
sudo apt-get install default-jdk
#update the path of java home in bashrc
sudo vi ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/default-java
export CATALINA_HOME=~/path/to/tomcat
  

#Save the bashrc  and restart it, there is . in the front
. ~/.bashrc
# Update the path of java in tomcat as well
sudo gedit <path to tomcat>/tomcat7/bin/catalina.sh

#add the following lines at the end, version might be different so use your not mine :) 
JAVA_HOME="/usr/lib/jvm/default-java"
JRE_HOME="
/usr/lib/jvm/default-java/jre"

#now lets start the tomcat
$CATALINA_HOME/bin/startup.sh
if it runs you are good to go, sometime it might says "touch, can't touch .../logs/catalina.out
This might be the problem related to permission so go ahead create a directory called logs under tomcat7 and create a file catalina.out

using other terminal find the ip address (docker inspect container_id) of your container  and enter following line in your browser
<ip address of container>:8080
it should so

It works !

Voila, you have a container running apache inside of it. :)
 I am new to blog writing so bear with me for a while. Let me know if you face any issue 

No comments:

Post a Comment

User Interface(UI) for Docker, Portainer

Portainer gives you access to a central overview of your Docker host or Swarm cluster. From the dashboard, you can easily access any manag...