Build a Tomcat 7 Image Based on Ubuntu 14.04

Source: Internet
Author: User
Tags docker run

Build a Tomcat 7 Image Based on Ubuntu 14.04

Build a Tomcat 7 Image Based on Ubuntu 14.04

1. Create a Dockerfile

# Pull base image  FROM ubuntu:14.04    MAINTAINER shencq "shencq@g-soft.com.cn"    # update source  RUN echo "deb http://archive.ubuntu.com/ubuntu trusty main universe"> /etc/apt/sources.list  RUN apt-get update    # Install curl  RUN apt-get -y install curl    # Install JDK 7  RUN cd /tmp &&  curl -L 'http://download.Oracle.com/otn-pub/java/jdk/7u65-b17/jdk-7u65-linux-x64.tar.gz' -H 'Cookie: oraclelicense=accept-securebackup-cookie; gpw_e24=Dockerfile' | tar -xz  RUN mkdir -p /usr/lib/jvm  RUN mv /tmp/jdk1.7.0_65/ /usr/lib/jvm/java-7-oracle/    # Set Oracle JDK 7 as default Java  RUN update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-oracle/bin/java 300     RUN update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-7-oracle/bin/javac 300       ENV JAVA_HOME /usr/lib/jvm/java-7-oracle/    # Install tomcat7  RUN cd /tmp && curl -L 'http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.8/bin/apache-tomcat-7.0.8.tar.gz' | tar -xz  RUN mv /tmp/apache-tomcat-7.0.8/ /opt/tomcat7/    ENV CATALINA_HOME /opt/tomcat7  ENV PATH $PATH:$CATALINA_HOME/bin    ADD tomcat7.sh /etc/init.d/tomcat7  RUN chmod 755 /etc/init.d/tomcat7    # Expose ports.  EXPOSE 8080    # Define default command.  ENTRYPOINT service tomcat7 start && tail -f /opt/tomcat7/logs/catalina.out 

2. Create the tomcat7.sh File

export JAVA_HOME=/usr/lib/jvm/java-7-oracle/export JAVA_OPTS="-Dfile.encoding=UTF-8 \-Dcatalina.logbase=/var/log/tomcatProd \-Dnet.sf.ehcache.skipUpdateCheck=true \-XX:+UseConcMarkSweepGC \-XX:+CMSClassUnloadingEnabled \-XX:+UseParNewGC \-XX:MaxPermSize=128m \-Xms512m -Xmx512m"export PATH=$JAVA_HOME/bin:$PATHTOMCAT_HOME=/opt/tomcat7SHUTDOWN_WAIT=20export CATALINA_OPTS="-Xmx512m"export CATALINA_BASE=/opt/tomcat7tomcat_pid() {  echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep $CATALINA_BASE | grep -v grep | awk '{ print $2 }'`}start() {  pid=$(tomcat_pid)  if [ -n "$pid" ]  thenecho "Tomcat is already running (pid: $pid)"  else    # Start tomcat    echo "Starting tomcat"    #ulimit -n 100000    umask 007    $TOMCAT_HOME/bin/startup.sh  fireturn 0}stop() {  pid=$(tomcat_pid)  if [ -n "$pid" ]  thenecho "Stoping Tomcat"    if [ "$USER" == "$TOMCAT_USER" ]    then         $TOMCAT_HOME/bin/shutdown.sh    else        /bin/su -p -s /bin/sh $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh    fi    let kwait=$SHUTDOWN_WAIT    count=0;    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]    doecho -n -e "\nwaiting for processes to exit";      sleep 1      let count=$count+1;    doneif [ $count -gt $kwait ]; thenecho -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"      kill -9 $pid    fielseecho "Tomcat is not running"  fireturn 0}case $1 instart)  start;;stop)  stop;;restart)  stop  start;;status)  pid=$(tomcat_pid)  if [ -n "$pid" ]  thenecho "Tomcat is running with pid: $pid"  elseecho "Tomcat is not running"  fi;;esacexit 0

3. Create an image

docker build -t shencq/tomcat7 . 

4. Run the image

docker run -d -p 8090:8080 shencq/tomcat7

5. Access tomcat

By default, tomcat occupies port 8080. when the container is started,-p 8090: 8080 is specified, and the port mapped to the host machine is 8090.

Http: // 

 

For more Tomcat tutorials, see the following:

Install and configure the Tomcat environment in CentOS 6.6

Install JDK + Tomcat in RedHat Linux 5.5 and deploy Java Projects

Tomcat authoritative guide (second edition) (Chinese/English hd pdf + bookmarks)

Tomcat Security Configuration and Performance Optimization

How to Use Xshell to view Tomcat real-time logs with Chinese garbled characters in Linux

Install JDK and Tomcat in CentOS 64-bit and set the Tomcat Startup Procedure

Install Tomcat in CentOS 6.5

Tomcat details: click here
Tomcat: click here

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.