Tomcat/JDK 镜像构建

发布时间: 更新时间: 总字数:543 阅读时间:2m 作者: IP上海 分享 网址

Java+Tomcat是进程常使用的Java Web服务器,该博文主要介绍如何使用Dockerfile构建Docker镜像

Tomcat7/JDK7

Dockerfile

Dockerfile
# Create by Xie Xianbin, For nginx Dockerfile
# v 0.0.1

# base image
FROM xiexianbin/centos6:base

# remark
MAINTAINER Xie Xianbin "xianbinxie@163.com"

# Dockerfile build cache
ENV REFRESHED_AT 2015-08-02

RUN rm -rf /etc/yum.repos.d/*
COPY Centos-6.repo /etc/yum.repos.d/
RUN yum clean all
RUN yum -y install wget curl vim tar
COPY apache-tomcat-7.0.63.tar.gz /opt/
COPY jdk-7u79-linux-x64.rpm /opt/

RUN rpm -ivh /opt/jdk-7u79-linux-x64.rpm
RUN tar -zxf /opt/apache-tomcat-7.0.63.tar.gz -C /opt/

RUN rm -rf /opt/jdk-7u79-linux-x64.rpm
RUN echo "sh /opt/apache-tomcat-7.0.63/bin/startup.sh" >> /etc/rc.local
RUN rm -rf /opt/apache-tomcat-7.0.63/webapps/docs
RUN rm -rf /opt/apache-tomcat-7.0.63/webapps/examples
RUN rm -rf /opt/apache-tomcat-7.0.63/webapps/host-manager
RUN rm -rf /opt/apache-tomcat-7.0.63/webapps/manager

RUN yum clean all
RUN history -c

EXPOSE 8080
ENTRYPOINT ["/bin/bash"]

Dockerfile 目录文件详情

相关文件下载地址

Docker build 命令

docker build -t xiexianbin/centos6:j7t7 .

docker build 过程

docker-build
$ docker build -t xiexianbin/centos6:j7t7 .
Sending build context to Docker daemon 146.9 MB
Sending build context to Docker daemon
Step 0 : FROM xiexianbin/centos6:base
  ---> a441d723c250
Step 1 : MAINTAINER Xie Xianbin "xianbinxie@163.com"
  ---> Running in bbe8641d7e60
  ---> 071e4124082c
Removing intermediate container bbe8641d7e60
Step 2 : ENV REFRESHED_AT 2015-08-09
  ---> Running in 000882f3c225
  ---> 42eff22932cf
...
Step 20 : ENTRYPOINT /bin/bash
---> Running in 451357081dde
---> 07ce97ebf5a7
Removing intermediate container 451357081dde
Successfully built 07ce97ebf5a7

登录Docker Hub

[root@iZ288u02izdZ ~]# docker login
Username: xiexianbin
Password:
Email: me@xiexianbin.cn
WARNING: login credentials saved in /root/.dockercfg.
Login Succeeded
[root@iZ288u02izdZ ~]#

docker push

docker login
docker push xiexianbin/centos6:j7t7

Tomcat8/JDK8

Dockerfile

# Create by Xie Xianbin, For centos7 jdk image
# v 1.0.0

# base image
FROM xiexianbin/centos7:latest

# remark
MAINTAINER Xie Xianbin "xianbinxie@163.com"

# Dockerfile build cache
ENV REFRESHED_AT 2016-07-29

RUN rm -rf /etc/yum.repos.d/*
COPY Centos-7.repo /etc/yum.repos.d/
RUN yum clean all
RUN yum -y install wget curl vim tar
COPY apache-tomcat-8.5.4.tar.gz /opt/
COPY jdk-8u101-linux-x64.rpm /opt/

RUN rpm -ivh /opt/jdk-8u101-linux-x64.rpm
RUN tar -zxf /opt/apache-tomcat-8.5.4.tar.gz -C /opt/

RUN rm -rf /opt/jdk-7u79-linux-x64.rpm
RUN echo "sh /opt/apache-tomcat-8.5.4/bin/startup.sh" >> /etc/rc.local
RUN rm -rf /opt/apache-tomcat-8.5.4/webapps/docs
RUN rm -rf /opt/apache-tomcat-8.5.4/webapps/examples
RUN rm -rf /opt/apache-tomcat-8.5.4/webapps/host-manager
RUN rm -rf /opt/apache-tomcat-8.5.4/webapps/manager

RUN yum clean all
RUN history -c

EXPOSE 8080
ENTRYPOINT ["/bin/bash"]

Dockerfile 目录文件详情

Docker相关文件下载地址: https://pan.baidu.com/s/1i5M22pv 密码: 2puc

Docker build 命令

docker build -t xiexianbin/centos7:j8t8 .

docker build 过程

[root@xiexianbin_cn docker]# docker build -t xiexianbin/centos7:j8t8 .
Sending build context to Docker daemon 175.2 MB
Sending build context to Docker daemon
Step 0 : FROM xiexianbin/centos7:latest
  ---> 8c2683e1bd97
Step 1 : MAINTAINER Xie Xianbin "xianbinxie@163.com"
  ---> Running in 9edb67344021
  ---> 87315882baef
...
Removing intermediate container 818f799b659b
Step 20 : ENTRYPOINT /bin/bash
  ---> Running in 0dc1fd834f39
  ---> c901722935c4
Removing intermediate container 0dc1fd834f39
Successfully built c901722935c4
[root@xiexianbin_cn docker]#

登录Docker Hub

[root@xiexianbin_cn ~]# docker login
Username: xiexianbin
Password:
Email: me@xiexianbin.cn
WARNING: login credentials saved in /root/.dockercfg.
Login Succeeded
[root@xiexianbin_cn ~]#
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数