频道栏目
首页 > 网络 > 其他 > 正文

无需申请自动送

2018-11-30 10:28:03           
收藏   我要投稿

利用Dockerfile制作java运行环境的镜像

无需申请自动送安装docker
无需申请自动送卸载旧版本
yumremovedocker\
docker-client\
docker-client-latest\
docker-common\
docker-latest\
docker-latest-logrotate\
docker-logrotate\
docker-selinux\
docker-engine-selinux\
docker-engine
无需申请自动送安装所需的包
yuminstall-yyum-utils\
device-mapper-persistent-data\
lvm2
无需申请自动送使用以下命令设置稳定存储库
yum-config-manager\
--add-repo\
https://download.docker.com/linux/centos/docker-ce.repo
无需申请自动送安装最新版本的DockerCE
yuminstalldocker-ce-y
[[email protected]]无需申请自动送dockerversion
Client:
Version:18.06.1-ce
APIversion:1.38
Goversion:go1.10.3
Gitcommit:e68fc7a
Built:TueAug2117:23:032018
OS/Arch:linux/amd64
Experimental:false
Server:
Engine:
Version:18.06.1-ce
APIversion:1.38(minimumversion1.12)
Goversion:go1.10.3
Gitcommit:e68fc7a
Built:TueAug2117:25:292018
OS/Arch:linux/amd64
Experimental:false
[[email protected]***tomcat-base]无需申请自动送systemctlenabledocker.service
[[email protected]***tomcat-base]无需申请自动送systemctlstartdocker

当前用到的环境是:Centos 7.5

Docker version 18.06.1-ce, build e68fc7a

1、先用操作系统的基础镜像把一些运行需要的环境装好在/app目录下创建相对应的文件目录

[[email protected]/app/]无需申请自动送mkdirdockerfile/{web/{nginx,tomcat,jdk,apache},system/{centos,ubuntu,redhat}}-pv
[[email protected]/app]无需申请自动送cddockerfile/system/centos/
[[email protected]/app/dockerfile/system/centos]无需申请自动送mkdircentos-7.5-base
[[email protected]/app/dockerfile/system/centos]无需申请自动送cdcentos-7.5-base

创建一个Dockerfile文件

[[email protected]***centos-7.5-base]无需申请自动送catDockerfile
无需申请自动送NginxBaseImage
FROMcentos:7.5.1804
LABELmaintaier"jiangwenhui<[email protected]>"
RUNyuminstall-yvimwgetpcrepcre-develzlibzlib-developensslopenssl-develiproutenet-toolsiotop

创建一个用于直接docker build脚本后续直接执行脚本即可

[[email protected]***centos-7.5-base]无需申请自动送catbuild-command.sh
无需申请自动送!/bin/bash
dockerbuild-t172.20.7.50/baseimages/centos-base:7.5.1804.
[[email protected]***centos-7.5-base]无需申请自动送

执行脚本创建新镜像

[[email protected]/app/dockerfile/system/centos/centos-7.5-base]无需申请自动送bashbuild-command.sh
SendingbuildcontexttoDockerdaemon3.072kB
Step1/3:FROMcentos:7.5.1804
--->76d6bc25b8a5
Step2/3:LABELmaintaier&无需申请自动送39;[email protected]&无需申请自动送39;
--->Usingcache
--->05ccd970d71d
Step3/3:RUNyuminstall-yvimwgetpcrepcre-develzlibzlib-developensslopenssl-develiproutenet-toolsiotop
--->Usingcache
--->73d683a54877
Successfullybuilt73d683a54877
Successfullytagged172.20.7.50/baseimages/centos-base:7.5.1804

2、利用制作好的基础环境镜像制作jdk的镜像从centos-7.5-base退出来在当前目录创建一个jdk1.8的目录.

[[email protected]/app/dockerfile/system/centos/centos-7.5-base]无需申请自动送cd..
[[email protected]/app/dockerfile/system/centos]无需申请自动送mkdirjdk1.8
[[email protected]/app/dockerfile/system/centos]无需申请自动送cdjdk1.8/

创建Dockerfile

[[email protected]***jdk1.8]无需申请自动送catDockerfile
FROM172.20.7.50/baseimages/centos-base:7.5.1804
LABELmaintainer"jiangwenhui<[email protected]>"
ADDjdk-8u191-linux-x64.tar.gz/usr/local/src/
RUNln-s/usr/local/src/jdk1.8.0_191//usr/local/jdk
ADDprofile/etc/profile
ENVJAVA_HOME/usr/local/jdk
ENVJRE_HOME$JAVA_HOME/jre
ENVCLASSPATH$JAVA_HOME/lib/:$JRE_HOME/lib/
ENVPATH$PATH:$JAVA_HOME/bin
RUNrm-rf/etc/localtime&&ln-snf/usr/share/zoneinfo/Asia/Shanghai/etc/localtime&&echo"Asia/Shanghai">/etc/timezone

上传jdk包到当前目录下:

复制/etc/profile文件到当前目录

[[email protected]***jdk1.8]无需申请自动送cp/etc/profile.

在profile最后添加jdk的环境变量

[[email protected]***jdk1.8]无需申请自动送tail-10profile
TZ=&无需申请自动送39;Asia/Shanghai&无需申请自动送39;
exportTZ
无需申请自动送java
exportJAVA_HOME=/usr/local/jdk
exportTOMCAT_HOME=/apps/tomcat
exportPATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$TOMCAT_HOME/bin:$PATH
exportCLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar

创建docker build的shell脚本

[[email protected]***jdk1.8]无需申请自动送catbuild-command.sh
无需申请自动送!/bin/bash
无需申请自动送
dockerbuild-t172.20.7.50/baseimages/centos7.5-jdk:8.162.

开始制作镜像

[[email protected]/app/dockerfile/system/centos/jdk1.8]无需申请自动送bashbuild-command.sh
SendingbuildcontexttoDockerdaemon189.8MB
Step1/10:FROM172.20.7.50/baseimages/centos-base:7.5.1804
--->73d683a54877
Step2/10:LABELmaintainer"jwh<[email protected]>"
--->Runningin65604dd1f392
Removingintermediatecontainer65604dd1f392
--->c4720603ce38
Step3/10:ADDjdk-8u162-linux-x64.tar.gz/usr/local/src/
--->bc98adffe1b4
Step4/10:RUNln-s/usr/local/src/jdk1.8.0_162//usr/local/jdk
--->Runningindf5a6f67f9fd
Removingintermediatecontainerdf5a6f67f9fd
--->0ae1af0416c6
Step5/10:ADDprofile/etc/profile
--->eee23a69c0c8
Step6/10:ENVJAVA_HOME/usr/local/jdk
--->Runninginedbef8563e83
Removingintermediatecontaineredbef8563e83
--->5f783f642054
Step7/10:ENVJRE_HOME$JAVA_HOME/jre
--->Runninginfa0e5f08e732
Removingintermediatecontainerfa0e5f08e732
--->28a4d31463d4
Step8/10:ENVCLASSPATH$JAVA_HOME/lib/:$JRE_HOME/lib/
--->Runningin3c4ebb04ac62
Removingintermediatecontainer3c4ebb04ac62
--->245f2dd82d52
Step9/10:ENVPATH$PATH:$JAVA_HOME/bin
--->Runningin4f5e6093f0a9
Removingintermediatecontainer4f5e6093f0a9
--->5be0e6261eea
Step10/10:RUNrm-rf/etc/localtime&&ln-snf/usr/share/zoneinfo/Asia/Shanghai/etc/localtime&&echo"Asia/Shanghai">/etc/timezone
--->Runningin52d8cb8463a8
Removingintermediatecontainer52d8cb8463a8
--->9fb867ae8c39
Successfullybuilt9fb867ae8c39
Successfullytagged172.20.7.50/baseimages/centos7.5-jdk:8.162

查看当前目录下的文件

[[email protected]***jdk1.8]无需申请自动送ls
build-command.shDockerfilejdk-8u191-linux-x64.tar.gzprofile

检查制作好的镜像是否能正常使用

[[email protected]***jdk1.8]无需申请自动送dockerrun-it--rm172.20.7.50/baseimages/centos7.5-jdk:8.162bash
[[email protected]/]无需申请自动送java-version
javaversion"1.8.0_191"
Java(TM)SERuntimeEnvironment(build1.8.0_191-b12)
JavaHotSpot(TM)64-BitServerVM(build25.191-b12,mixedmode)
[[email protected]/]无需申请自动送date+&无需申请自动送39;%F%T&无需申请自动送39;
2018-11-2910:42:57
[[email protected]/]无需申请自动送exit
exit
[[email protected]***jdk1.8]无需申请自动送

3、做Tomcat的镜像进入之前建好的/app/dockerfile/web/tomcat下,创建一个tomcat-base目录

[[email protected]~]无需申请自动送cd/app/dockerfile/web/tomcat
[[email protected]/app/dockerfile/web/tomcat]无需申请自动送mkdirtomcat-base
[[email protected]***tomcat]无需申请自动送cdtomcat-base/

创建Dockerfile

[[email protected]***tomcat-base]无需申请自动送catDockerfile
FROM172.20.7.50/baseimages/centos7.5-jdk:8.162
LABELmaintainer"jiangwenhui<[email protected]>"
RUNmkdir/apps
ADDapache-tomcat-8.5.35.tar.gz/apps
RUNln-s/apps/apache-tomcat-8.5.35/apps/tomcat

创建docker build脚本

[[email protected]***tomcat-base]无需申请自动送catbuild-command.sh
无需申请自动送!/bin/bash
dockerbuild-t172.20.7.50/baseimages/centos-tomcat:8.5.35.

执行创建镜像文件:

[[email protected]/app/dockerfile/web/tomcat/tomcat-base]无需申请自动送bashbuild-command.sh
SendingbuildcontexttoDockerdaemon9.625MB
Step1/5:FROM172.20.7.50/baseimages/centos7.5-jdk:8.162
--->9fb867ae8c39
Step2/5:LABELmaintainer"jiangwenhui<[email protected]>"
--->Runningin9ce6fc4d2850
Removingintermediatecontainer9ce6fc4d2850
--->b68755061b28
Step3/5:RUNmkdir/apps
--->Runninginb483c6b127f2
Removingintermediatecontainerb483c6b127f2
--->605c1a048a5f
Step4/5:ADDapache-tomcat-8.5.35.tar.gz/apps
--->3c44f96ed41c
Step5/5:RUNln-s/apps/apache-tomcat-8.5.35/apps/tomcat
--->Runningin4c1aa39a6c92
Removingintermediatecontainer4c1aa39a6c92
--->9b3bc4f58cc9
Successfullybuilt9b3bc4f58cc9
Successfullytagged172.20.7.50/baseimages/centos-tomcat:8.5.35

利用创建好的镜像起一个容器检查下是否成功制作好,启动时加上-p暴露端口,在物理机上测试下

[[email protected]/app/dockerfile/web/tomcat/tomcat-base]无需申请自动送dockerrun-it-p8802:8080172.20.7.50/baseimages/centos-tomcat:8.5.35bash
[[email protected]/]无需申请自动送cd/apps/
[[email protected]]无需申请自动送ll
total0
drwxr-xr-x9rootroot220Nov2222:08apache-tomcat-8.5.35
lrwxrwxrwx1rootroot26Nov2222:08tomcat->/apps/apache-tomcat-8.5.35
[[email protected]]无需申请自动送./tomcat/bin/catalina.shstart
UsingCATALINA_BASE:/apps/tomcat
UsingCATALINA_HOME:/apps/tomcat
UsingCATALINA_TMPDIR:/apps/tomcat/temp
UsingJRE_HOME:/usr/local/jdk/jre
UsingCLASSPATH:/apps/tomcat/bin/bootstrap.jar:/apps/tomcat/bin/tomcat-juli.jar
Tomcatstarted.
相关TAG标签 Dockerfile 使用
上一篇:Ubuntu中IPFS私有多结点部署
下一篇:如何加快win10开机速度
相关文章
图文推荐

关于我们 | 联系我们 | 服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑--致力于做实用的IT技术学习网站