共计 3336 个字符,预计需要花费 9 分钟才能阅读完成。
基于 Ubuntu 14.04 构建 Tomcat 7 镜像
1、创建 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、创建 tomcat7.sh 文件
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:$PATH
TOMCAT_HOME=/opt/tomcat7
SHUTDOWN_WAIT=20
export CATALINA_OPTS="-Xmx512m"
export CATALINA_BASE=/opt/tomcat7
tomcat_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" ]
then
echo "Tomcat is already running (pid: $pid)"
else
# Start tomcat
echo "Starting tomcat"
#ulimit -n 100000
umask 007
$TOMCAT_HOME/bin/startup.sh
fi
return 0
}
stop() {pid=$(tomcat_pid)
if [-n "$pid" ]
then
echo "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 ]
do
echo -n -e "\nwaiting for processes to exit";
sleep 1
let count=$count+1;
done
if [$count -gt $kwait]; then
echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
kill -9 $pid
fi
else
echo "Tomcat is not running"
fi
return 0
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
pid=$(tomcat_pid)
if [-n "$pid" ]
then
echo "Tomcat is running with pid: $pid"
else
echo "Tomcat is not running"
fi
;;
esac
exit 0
3、构建镜像
docker build -t shencq/tomcat7 .
4、运行镜像
docker run -d -p 8090:8080 shencq/tomcat7
5、访问 tomcat
默认情况下,tomcat 会占用 8080 端口,刚才在启动 container 的时候,指定了 -p 8090:8080,映射到宿主机端口就是 8090。
http://<host>:8090 #host 为主机 IP
更多 Tomcat 相关教程见以下内容:
CentOS 6.6 下安装配置 Tomcat 环境 http://www.linuxidc.com/Linux/2015-08/122234.htm
RedHat Linux 5.5 安装 JDK+Tomcat 并部署 Java 项目 http://www.linuxidc.com/Linux/2015-02/113528.htm
Tomcat 权威指南(第二版)(中英高清 PDF 版 + 带书签) http://www.linuxidc.com/Linux/2015-02/113062.htm
Tomcat 安全配置与性能优化 http://www.linuxidc.com/Linux/2015-02/113060.htm
Linux 下使用 Xshell 查看 Tomcat 实时日志中文乱码解决方案 http://www.linuxidc.com/Linux/2015-01/112395.htm
CentOS 64-bit 下安装 JDK 和 Tomcat 并设置 Tomcat 开机启动操作步骤 http://www.linuxidc.com/Linux/2015-01/111485.htm
CentOS 6.5 下安装 Tomcat http://www.linuxidc.com/Linux/2015-01/111415.htm
Tomcat 的详细介绍:请点这里
Tomcat 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-04/130317.htm