(1)准备工作:
创建tomcat7.0_jdk1.6文件夹,从www.oracle.com上下载sun_jdk 1.6压缩包,解压为jdk目录。
创建Dockerfile和run.sh文件
[[email protected] ~]# mkdir tomcat7.0_jdk1.6
[[email protected] ~]# cd tomcat7.0_jdk1.6/
[[email protected] tomcat7.0_jdk1.6]# touch Dockerfile run.sh
[[email protected] tomcat7.0_jdk1.6]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.zip
--2017-11-27 22:31:47-- https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.zip
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.6.178, 2402:f000:1:416:101:6:6:177
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.6.178|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9588812 (9.1M) [application/zip]
Saving to: ‘apache-tomcat-7.0.82.zip’
100%[================================================================================================================>] 9,588,812 3.38MB/s in 2.7s
2017-11-27 22:31:50 (3.38 MB/s) - ‘apache-tomcat-7.0.82.zip’ saved [9588812/9588812]
解压后,tomcat7.0_jdk1.6目录底下应如下所示(多余的压缩包已经被删除):
[[email protected] tomcat7.0_jdk1.6]# rz -y 上传jdk-6u45-linux-x64.bin包
[[email protected] tomcat7.0_jdk1.6]# chmod 755 jdk-6u45-linux-x64.bin
[[email protected] tomcat7.0_jdk1.6]# ./jdk-6u45-linux-x64.bin
[[email protected] tomcat7.0_jdk1.6]# ls
apache-tomcat-7.0.82 apache-tomcat-7.0.82.zip Dockerfile jdk1.6.0_45 jdk-6u45-linux-x64.bin jdk-6u45-linux-x64.zip run.sh
[[email protected] tomcat7.0_jdk1.6]# rm -f jdk-6u45-linux-x64.bin jdk-6u45-linux-x64.zip apache-tomcat-7.0.82.zip
[[email protected] tomcat7.0_jdk1.6]# ls
apache-tomcat-7.0.82 Dockerfile jdk1.6.0_45 run.sh
(2)编写Dockerfile文件
[[email protected] tomcat7.0_jdk1.6]# cat Dockerfile
#设置继承来自镜像
FROM docker.io/centos:latest
#下面是一些创建这的基本信息
MAINTAINER waitfish from dockerpool.com
#设置环境变量,所以操作都是非交互式的
ENV DEBIAN_FRONTEND noninteractive
RUN echo "Asia/Shanghai" > /etc/timezone
#注意这里要更改系统的时区设置,因为在Web应用中经常会用到时区这个系统变量,默认的centos会让你的应用程序发生不可思议的效果
#设置tomcat对的环境变量,若读者有其他的环境变量需要设置,也可以在这里添加:
ENV CATALINA_HOME /tomcat
ENV JAVA_HOME /jdk
#复制tomcat和jdk文件到镜像中
ADD apache-tomcat-7.0.82 /tomcat
ADD jdk1.6.0_45 /jdk
#ADD create_tomcat_admin_user.sh /create_tomcat_admin_user.sh
ADD run.sh /run.sh
RUN chmod +x /*.sh
RUN chmod +x /tomcat/bin/*.sh
EXPOSE 8080
CMD ["/run.sh"]
(3)建立tomcat7.0:jdk1.6镜像
[[email protected] tomcat7.0_jdk1.6]# docker build -t tomcat7.0:jdk1.6 .
[[email protected] tomcat7.0_jdk1.6]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat7.0 jdk1.6 581265694089 6 seconds ago 439.8 MB
......
(4)启动一个tomcat容器进行测试
[[email protected] tomcat7.0_jdk1.6]# docker run -d -P tomcat7.0:jdk1.6
ac6d662434ffb9435740d0f452599e12349903f4387775155f0d7e057eac6a33
(5)查看映射的端口信息:
[[email protected] tomcat7.0_jdk1.6]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ac6d662434ff tomcat7.0:jdk1.6 "/run.sh" 21 minutes ago Up 21 minutes 0.0.0.0:32820->8080/tcp thirsty_montalcini
(6)在本地使用浏览器登录Tomcat管理界面,访问10.0.0.10:32820,如下图所示:
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
tomcat设置密码登录
(1)更改Dockerfile配置文件
[[email protected] tomcat7.0_jdk1.6]# cat Dockerfile
#设置继承来自镜像
FROM docker.io/centos:latest
#下面是一些创建这的基本信息
MAINTAINER waitfish from dockerpool.com
#设置环境变量,所以操作都是非交互式的
ENV DEBIAN_FRONTEND noninteractive
RUN echo "Asia/Shanghai" > /etc/timezone #&& \
#dpkg-reconfigure -f noninteractive tzdata
#注意这里要更改系统的时区设置,因为在Web应用中经常会用到时区这个系统变量,默认的centos会让你的应用程序发生不可思议的效果
#安装跟tomcat用户认证相关的软件<-------------修改处
RUN yum update
RUN yum install -y wget pwgen ca-certificates && yum clean all
#设置tomcat对的环境变量,若读者有其他的环境变量需要设置,也可以在这里添加:
ENV CATALINA_HOME /tomcat
ENV JAVA_HOME /jdk
#复制tomcat和jdk文件到镜像中
ADD apache-tomcat-7.0.82 /tomcat
ADD jdk1.6.0_45 /jdk
#<------修改处
ADD create_tomcat_admin_user.sh /create_tomcat_admin_user.sh
ADD run.sh /run.sh
RUN chmod +x /*.sh
RUN chmod +x /tomcat/bin/*.sh
EXPOSE 8080
CMD ["/run.sh"]
*********************************************************************************************
附件:
apache-tomcat-7.0.82 http://down.51cto.com/data/2368971
jdk-6u45-linux-x64.bin http://down.51cto.com/data/2369015