使用 Dockerfile 构建 jdk7 - tomcat7 镜像

发布时间: 更新时间: 总字数:1268 阅读时间:3m 作者: 分享

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

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 目录文件详情

Dockerfile build centos base image

Docker相关文件下载地址:http://pan.baidu.com/s/1hqIWyC8

Docker build 命令

docker build -t xiexianbin/centos6:j7t7 .

docker build 过程

[root@iZ288u02izdZ docker]# 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
Removing intermediate container 000882f3c225
Step 3 : RUN rm -rf /etc/yum.repos.d/*
 ---> Running in 3f2057c68738
 ---> 2aecbcdd36f0
Removing intermediate container 3f2057c68738
Step 4 : COPY Centos-6.repo /etc/yum.repos.d/
 ---> d95f5ceec00c
Removing intermediate container 18de715ea08b
Step 5 : RUN yum clean all
 ---> Running in bc38b504651c
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up Everything
 ---> a8fa6351e2e9
Removing intermediate container bc38b504651c
Step 6 : RUN yum -y install wget curl vim tar
 ---> Running in ec65dd419d62
Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package curl.x86_64 0:7.19.7-40.el6_6.4 will be updated
---> Package curl.x86_64 0:7.19.7-46.el6 will be an update
--> Processing Dependency: libcurl = 7.19.7-46.el6 for package: curl-7.19.7-46.el6.x86_64
---> Package tar.x86_64 2:1.23-13.el6 will be installed
---> Package vim-enhanced.x86_64 2:7.4.629-5.el6 will be installed
--> Processing Dependency: vim-common = 2:7.4.629-5.el6 for package: 2:vim-enhanced-7.4.629-5.el6.x86_64
--> Processing Dependency: which for package: 2:vim-enhanced-7.4.629-5.el6.x86_64
--> Processing Dependency: perl(:MODULE_COMPAT_5.10.1) for package: 2:vim-enhanced-7.4.629-5.el6.x86_64
--> Processing Dependency: libperl.so()(64bit) for package: 2:vim-enhanced-7.4.629-5.el6.x86_64
--> Processing Dependency: libgpm.so.2()(64bit) for package: 2:vim-enhanced-7.4.629-5.el6.x86_64
---> Package wget.x86_64 0:1.12-5.el6_6.1 will be installed
--> Running transaction check
---> Package gpm-libs.x86_64 0:1.20.6-12.el6 will be installed
---> Package libcurl.x86_64 0:7.19.7-40.el6_6.4 will be updated
---> Package libcurl.x86_64 0:7.19.7-46.el6 will be an update
---> Package perl.x86_64 4:5.10.1-141.el6 will be installed
--> Processing Dependency: perl(version) for package: 4:perl-5.10.1-141.el6.x86_64
--> Processing Dependency: perl(Pod::Simple) for package: 4:perl-5.10.1-141.el6.x86_64
--> Processing Dependency: perl(Module::Pluggable) for package: 4:perl-5.10.1-141.el6.x86_64
---> Package perl-libs.x86_64 4:5.10.1-141.el6 will be installed
---> Package vim-common.x86_64 2:7.4.629-5.el6 will be installed
--> Processing Dependency: vim-filesystem for package: 2:vim-common-7.4.629-5.el6.x86_64
---> Package which.x86_64 0:2.19-6.el6 will be installed
--> Running transaction check
---> Package perl-Module-Pluggable.x86_64 1:3.90-141.el6 will be installed
---> Package perl-Pod-Simple.x86_64 1:3.13-141.el6 will be installed
--> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.13-141.el6.x86_64
---> Package perl-version.x86_64 3:0.77-141.el6 will be installed
---> Package vim-filesystem.x86_64 2:7.4.629-5.el6 will be installed
--> Running transaction check
---> Package perl-Pod-Escapes.x86_64 1:1.04-141.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                    Arch        Version                 Repository
                                                                           Size
================================================================================
Installing:
 tar                        x86_64      2:1.23-13.el6           base      809 k
 vim-enhanced               x86_64      2:7.4.629-5.el6         base      1.0 M
 wget                       x86_64      1.12-5.el6_6.1          base      483 k
Updating:
 curl                       x86_64      7.19.7-46.el6           base      196 k
Installing for dependencies:
 gpm-libs                   x86_64      1.20.6-12.el6           base       28 k
 perl                       x86_64      4:5.10.1-141.el6        base       10 M
 perl-Module-Pluggable      x86_64      1:3.90-141.el6          base       40 k
 perl-Pod-Escapes           x86_64      1:1.04-141.el6          base       33 k
 perl-Pod-Simple            x86_64      1:3.13-141.el6          base      213 k
 perl-libs                  x86_64      4:5.10.1-141.el6        base      578 k
 perl-version               x86_64      3:0.77-141.el6          base       52 k
 vim-common                 x86_64      2:7.4.629-5.el6         base      6.7 M
 vim-filesystem             x86_64      2:7.4.629-5.el6         base       15 k
 which                      x86_64      2.19-6.el6              base       38 k
Updating for dependencies:
 libcurl                    x86_64      7.19.7-46.el6           base      168 k

Transaction Summary
================================================================================
Install      13 Package(s)
Upgrade       2 Package(s)

Total download size: 21 M
Downloading Packages:
--------------------------------------------------------------------------------
Total                                           5.0 MB/s |  21 MB     00:04     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid: "CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>"
 From  : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : 1:perl-Pod-Escapes-1.04-141.el6.x86_64                      1/17 
  Installing : 3:perl-version-0.77-141.el6.x86_64                          2/17 
  Installing : 1:perl-Module-Pluggable-3.90-141.el6.x86_64                 3/17 
  Installing : 4:perl-libs-5.10.1-141.el6.x86_64                           4/17 
  Installing : 1:perl-Pod-Simple-3.13-141.el6.x86_64                       5/17 
  Installing : 4:perl-5.10.1-141.el6.x86_64                                6/17 
  Updating   : libcurl-7.19.7-46.el6.x86_64                                7/17 
  Installing : which-2.19-6.el6.x86_64                                     8/17 
install-info: No such file or directory for /usr/share/info/which.info.gz
  Installing : 2:vim-filesystem-7.4.629-5.el6.x86_64                       9/17 
  Installing : 2:vim-common-7.4.629-5.el6.x86_64                          10/17 
  Installing : gpm-libs-1.20.6-12.el6.x86_64                              11/17 
  Installing : 2:vim-enhanced-7.4.629-5.el6.x86_64                        12/17 
  Updating   : curl-7.19.7-46.el6.x86_64                                  13/17 
  Installing : 2:tar-1.23-13.el6.x86_64                                   14/17 
  Installing : wget-1.12-5.el6_6.1.x86_64                                 15/17 
install-info: No such file or directory for /usr/share/info/wget.info.gz
  Cleanup    : curl-7.19.7-40.el6_6.4.x86_64                              16/17 
  Cleanup    : libcurl-7.19.7-40.el6_6.4.x86_64                           17/17 
  Verifying  : 1:perl-Pod-Simple-3.13-141.el6.x86_64                       1/17 
  Verifying  : gpm-libs-1.20.6-12.el6.x86_64                               2/17 
  Verifying  : 2:vim-filesystem-7.4.629-5.el6.x86_64                       3/17 
  Verifying  : 3:perl-version-0.77-141.el6.x86_64                          4/17 
  Verifying  : 1:perl-Module-Pluggable-3.90-141.el6.x86_64                 5/17 
  Verifying  : which-2.19-6.el6.x86_64                                     6/17 
  Verifying  : 2:vim-enhanced-7.4.629-5.el6.x86_64                         7/17 
  Verifying  : wget-1.12-5.el6_6.1.x86_64                                  8/17 
  Verifying  : 2:tar-1.23-13.el6.x86_64                                    9/17 
  Verifying  : 2:vim-common-7.4.629-5.el6.x86_64                          10/17 
  Verifying  : 1:perl-Pod-Escapes-1.04-141.el6.x86_64                     11/17 
  Verifying  : curl-7.19.7-46.el6.x86_64                                  12/17 
  Verifying  : 4:perl-libs-5.10.1-141.el6.x86_64                          13/17 
  Verifying  : libcurl-7.19.7-46.el6.x86_64                               14/17 
  Verifying  : 4:perl-5.10.1-141.el6.x86_64                               15/17 
  Verifying  : libcurl-7.19.7-40.el6_6.4.x86_64                           16/17 
  Verifying  : curl-7.19.7-40.el6_6.4.x86_64                              17/17 

Installed:
  tar.x86_64 2:1.23-13.el6            vim-enhanced.x86_64 2:7.4.629-5.el6       
  wget.x86_64 0:1.12-5.el6_6.1       

Dependency Installed:
  gpm-libs.x86_64 0:1.20.6-12.el6                                               
  perl.x86_64 4:5.10.1-141.el6                                                  
  perl-Module-Pluggable.x86_64 1:3.90-141.el6                                   
  perl-Pod-Escapes.x86_64 1:1.04-141.el6                                        
  perl-Pod-Simple.x86_64 1:3.13-141.el6                                         
  perl-libs.x86_64 4:5.10.1-141.el6                                             
perl-version.x86_64 3:0.77-141.el6                                            
vim-common.x86_64 2:7.4.629-5.el6                                             
vim-filesystem.x86_64 2:7.4.629-5.el6                                         
which.x86_64 0:2.19-6.el6                                                     

Updated:
  curl.x86_64 0:7.19.7-46.el6                                                   

Dependency Updated:
  libcurl.x86_64 0:7.19.7-46.el6                                                

Complete!
 ---> 88689e38f220
Removing intermediate container ec65dd419d62
Step 7 : COPY apache-tomcat-7.0.63.tar.gz /opt/
 ---> ad0387bbe246
Removing intermediate container 181a6f22162b
Step 8 : COPY jdk-7u79-linux-x64.rpm /opt/
 ---> f01fa97c42df
Removing intermediate container 25788c50f5ab
Step 9 : RUN rpm -ivh /opt/jdk-7u79-linux-x64.rpm
 ---> Running in 03534ef5bab1
Preparing...                ##################################################
jdk                         ##################################################
Unpacking JAR files...
    rt.jar...
    jsse.jar...
    charsets.jar...
    tools.jar...
    localedata.jar...
    jfxrt.jar...
 ---> 0a9937703ab3
Removing intermediate container 03534ef5bab1
  Step 10 : RUN tar -zxf /opt/apache-tomcat-7.0.63.tar.gz -C /opt/
   ---> Running in 4be85d9f07cd
   ---> 855ac41f0a61
  Removing intermediate container 4be85d9f07cd
  Step 11 : RUN rm -rf /opt/jdk-7u79-linux-x64.rpm
   ---> Running in 632e5160adf8
   ---> 6562fb166a74
  Removing intermediate container 632e5160adf8
  Step 12 : RUN echo "sh /opt/apache-tomcat-7.0.63/bin/startup.sh" >> /etc/rc.local
   ---> Running in 59aaa7e56641
   ---> 35ae4aee9889
  Removing intermediate container 59aaa7e56641
  Step 13 : RUN rm -rf /opt/apache-tomcat-7.0.63/webapps/docs
   ---> Running in 968d74db78ef
   ---> 0ed211120bf1
  Removing intermediate container 968d74db78ef
  Step 14 : RUN rm -rf /opt/apache-tomcat-7.0.63/webapps/examples
   ---> Running in b6cdc019c21b
   ---> 143b924a8404
  Removing intermediate container b6cdc019c21b
 Step 15 : RUN rm -rf /opt/apache-tomcat-7.0.63/webapps/host-manager
  ---> Running in 8945c73aff7b
  ---> 4ab6c5e9f9e3
 Removing intermediate container 8945c73aff7b
 Step 16 : RUN rm -rf /opt/apache-tomcat-7.0.63/webapps/manager
  ---> Running in 53724b936445
  ---> cd64ae77cb8f
 Removing intermediate container 53724b936445
 Step 17 : RUN yum clean all
  ---> Running in a5045f343532
 Loaded plugins: fastestmirror
 Cleaning repos: base extras updates
 Cleaning up Everything
 Cleaning up list of fastest mirrors
  ---> 6b370f85d7ee
 Removing intermediate container a5045f343532
 Step 18 : RUN history -c
  ---> Running in 741e90da4aca
  ---> 7bb45ed16c25
 Removing intermediate container 741e90da4aca
 Step 19 : EXPOSE 8080
  ---> Running in 2b9f7b72728e
  ---> 6e32d46568a3
 Removing intermediate container 2b9f7b72728e
 Step 20 : ENTRYPOINT /bin/bash
  ---> Running in 451357081dde
  ---> 07ce97ebf5a7
 Removing intermediate container 451357081dde
 Successfully built 07ce97ebf5a7
 [root@iZ288u02izdZ docker]# 

登录Docker Hub

[root@iZ288u02izdZ ~]# docker login
Username: xiexianbin
Password: 
Email: a.b@hotmail.com
WARNING: login credentials saved in /root/.dockercfg.
Login Succeeded
[root@iZ288u02izdZ ~]# 

docker push

Dockerfile build centos base image

Home Archives Categories Tags Docs