Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Dockerfile to make a Mirror of java running Environment

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "how to use Dockerfile to create a mirror of the java operating environment", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use Dockerfile to make a mirror of the java operating environment" article.

The environment currently used is:

Centos 7.5

Docker-ce 18.06.1-ce

1. Use the basic image of centos7.5.1804 to install some environments needed for operation.

Create a corresponding file directory under the / app directory

[root@node2 / app/] # mkdir dockerfile/ {web/ {nginx,tomcat,jdk,apache}, system/ {centos,ubuntu,redhat}}-pv [root@node2 / app] # cd dockerfile/system/centos/ [root@node2 / app/dockerfile/system/centos] # mkdir centos-7.5-base [root@node2 / app/dockerfile/system/centos] # cd centos-7.5-base

Create a dockerfile file

[root@node2 / app/dockerfile/system/centos/centos-7.5-base] # vim dockerfile # nginx base imagefrom centos:7.5.1804label maintaier "mr.luo" run yum install-y vim wget pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop

Create a script for direct docker build and then directly execute the script

[root@node2 / app/dockerfile/system/centos/centos-7.5-base] # vim build-command.sh #! / bin/bashdocker build- t 172.20.7.50/baseimages/centos-base:7.5.1804.

Execute a script to create a new image

[root@node2 / app/dockerfile/system/centos/centos-7.5-base] # bash build-command.sh sending build context to docker daemon 3.072kbstep 1 run yum install 3: from centos:7.5.1804--- > 76d6bc25b8a5step 2 Accord 3: label maintaier 'mr.luo@dklwj.com'--- > using cache--- > 05ccd970d71dstep 3 Accord 3: run yum install-y vim wget pcre pcre-devel zlib zlib-devel openssl openssl-devel iproute net-tools iotop--- > using cache--- > 73d683a54877successfully built 73d683a54877successfully tagged 172.20.7.50/baseimages/centos-base:7.5.1804

2. Use the basic environment image to create the image of jdk

Exit from centos-7.5-base to create a jdk1.8 directory in the current directory.

[root@node2 / app/dockerfile/system/centos/centos-7.5-base] # cd.. [root@node2 / app/dockerfile/system/centos] # mkdir jdk1.8 [root@node2 / app/dockerfile/system/centos] # cd jdk1.8/

Create dockerfile

[root@node2 / app/dockerfile/system/centos/jdk1.8] # vim dockerfile from 172.20.7.50/baseimages/centos-base:7.5.1804label maintainer "mr.luo" add jdk-8u162-linux-x64.tar.gz / usr/local/src/run ln-s / usr/local/src/jdk1.8.0_162/ / usr/local/jdkadd profile / etc/profileenv java_home/ usr/local/jdkenv jre_home $java_home/jreenv classpath $java_home/lib/ : $jre_home/lib/env path $path:$java_home/binrun rm-rf / etc/localtime & & ln-snf / usr/share/zoneinfo/asia/shanghai / etc/localtime & & echo "asia/shanghai" > / etc/timezone

Upload the jdk package to the current directory:

Copy the / etc/profile file to the current directory

[root@node2 / app/dockerfile/system/centos/jdk1.8] # cp profile / etc/profile

Add the environment variable of jdk at the end of profile

[root@node2 / app/dockerfile/system/centos/jdk1.8] # vim profile export java_home=/usr/local/jdkexport tomcat_home=/apps/tomcatexport path=$java_home/bin:$java_home/jre/bin:$tomcat_home/bin:$pathexport classpath=.$classpath:$java_home/lib:$java_home/jre/lib:$java_home/lib/tools.jar

Create a shell script for docker build

[root@node2 / app/dockerfile/system/centos/jdk1.8] # vim build-command.sh #! / bin/bash#docker build- t 172.20.7.50/baseimages/centos7.5-jdk:8.162.

Start making a mirror image

[root@node2 / app/dockerfile/system/centos/jdk1.8] # bash build-command.sh sending build context to docker daemon 189.8mb step 1gam10: from 172.20.7.50/baseimages/centos-base:7.5.1804-> 73d683a54877 step 2x10: label maintainer "mr.luo"-> running in 65604dd1f392 removing intermediate container 65604dd1f392-- > c4720603ce38 step 3x10: add jdk-8u162-linux-x64.tar.gz / usr/local/src/ -> bc98adffe1b4 step 4 env java_home/ usr/local/jdk 10: run ln-s / usr/local/src/jdk1.8.0_162/ / usr/local/jdk-- > running in df5a6f67f9fd removing intermediate container df5a6f67f9fd-- > 0ae1af0416c6 step 5 etc/profile 10: add profile / etc/profile-- > eee23a69c0c8 step 6 env java_home/ usr/local/jdk 10: env java_home/ usr/local/jdk-- > running in edbef8563e83 removing intermediate container edbef8563e83-- > 5f783f642054 step 7 shock 10: env jre_home $java_home/jre -> running in fa0e5f08e732 removing intermediate container fa0e5f08e732-> 28a4d31463d4 step 8 5be0e6261eea step 10: env classpath $java_home/lib/:$jre_home/lib/-- > running in 3c4ebb04ac62 removing intermediate container 3c4ebb04ac62-- > 245f2dd82d52 step 9 5be0e6261eea step 10: env path $path:$java_home/bin-- > 5be0e6261eea step 10 5be0e6261eea step 10: run rm-rf / etc/localtime & & ln-snf / usr/share/zoneinfo/asia/shanghai / etc/ Localtime & & echo "asia/shanghai" > / etc/timezone-> running in 52d8cb8463a8 removing intermediate container 52d8cb8463a8-- > 9fb867ae8c39 successfully built 9fb867ae8c39 successfully tagged 172.20.7.50/baseimages/centos7.5-jdk:8.162

View the files in the current directory

[root@node2 / app/dockerfile/system/centos/jdk1.8] # lsbuild-command.sh dockerfile jdk-8u162-linux-x64.tar.gz profile

Check whether the finished image can be used properly.

[root@node2 / app/dockerfile/system/centos/jdk1.8] # docker run-it-- rm 172.20.7.50/baseimages/centos7.5-jdk:8.162 bash [root@919844b164dc /] # java-version java version "1.8.0m162" java (tm) se runtime environment (build 1.8.0_162-b12) java hotspot (tm) 64-bit server vm (build 25.162-b12, mixed mode) [root@919844b164dc /] # datethu nov 22 21:17:49 cst 2018 [root@919844b164dc /] # exitexit

3. Mirror the tomcat

Go to the previously built / app/dockerfile/web/tomcat and create a tomcat-base directory

[root@node2 ~] # cd / app/dockerfile/web/tomcat [root@node2 / app/dockerfile/web/tomcat] # mkdir tomcat-base

Create dockerfile

[root@node2 / app/dockerfile/web/tomcat/tomcat-base] # vim dockerfile from 172.20.7.50/baseimages/centos7.5-jdk:8.162label maintainer "mr.luo" run mkdir / appsadd apache-tomcat-8.5.33.tar.gz / appsrun ln-s / apps/apache-tomcat-8.5.33 / apps/tomcat

Create a docker build script

[root@node2 / app/dockerfile/web/tomcat/tomcat-base] # vim build-command.sh #! / bin/bashdocker build- t 172.20.7.50/baseimages/centos-tomcat:8.5.33.

Perform the creation of an image file:

[root@node2 / app/dockerfile/web/tomcat/tomcat-base] # bash build-command.sh sending build context to docker daemon 9.625mb step 1 running in 9ce6fc4d2850 removing intermediate container 9ce6fc4d2850 5: from 172.20.7.50/baseimages/centos7.5-jdk:8.162-> 9fb867ae8c39 step 2 mr.luo 5: label maintainer "mr.luo"-> running in 9ce6fc4d2850 removing intermediate container 9ce6fc4d2850-- > b68755061b28 step 3 run mkdir 5: run mkdir / apps-- > running in b483c6b127f2 removing intermediate container b483c6b127f2-- -> 605c1a048a5f step 4 apps 5: add apache-tomcat-8.5.33.tar.gz / apps-- > 3c44f96ed41c step 5 Accord 5: run ln-s / apps/apache-tomcat-8.5.33 / apps/tomcat-> running in 4c1aa39a6c92 removing intermediate container 4c1aa39a6c92-- > 9b3bc4f58cc9 successfully built 9b3bc4f58cc9 successfully tagged 172.20.7.50/baseimages/centos-tomcat:8.5.33

Use the created image to set up a container to check whether it is made successfully, add-p to expose the port at startup, and test it on the physical machine.

[root@node2 / app/dockerfile/web/tomcat/tomcat-base] # docker run-it-p 8802 docker run 8080 172.20.7.50/baseimages/centos-tomcat:8.5.33 bash [root@917b2c2262a3 /] # cd / apps/ [root@917b2c2262a3 apps] # lltotal 0drwxr-xr-x 9 root root 220 nov 22 22:08 apache-tomcat-8.5.33lrwxrwxrwx 1 root root 26 nov 22 22:08 tomcat- > / apps/apache-tomcat-8.5.33 [root@917b2c2262a3 apps] #. / tomcat/bin/catalina.sh startusing catalina_base: / apps/tomcatusing catalina_home: / apps/tomcatusing catalina_tmpdir: / apps/tomcat/tempusing jre_home: / usr/local/jdk/jreusing classpath: / apps/tomcat/bin/bootstrap.jar:/apps/tomcat/bin/tomcat-juli.jartomcat started.

Test with a browser on the client side

The above is the content of this article on "how to use Dockerfile to make an image of the java operating environment". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report