Docker构建jdk镜像并部署私服

  • 构建jdk镜像

https://reproductivepsych.org/dzdhv1xl 1、pull centos7的镜像

http://santondownham.org/7xiy44juv docker pull centos:7

http://champspublichealth.com/twvjlzc9 2、下载jdk-8u181-linux-x64.tar.gz,上传到centos中/usr/local/jdk8docker(这里我是在windows下下载的上传到了服务器上,使用的工具使rz,可以通过yum安装,安装命令:
yum install -y lrzsz

3、配置Dockerfile(位置和jdk一致 :/usr/local/jdk8docker 中)

http://www.cancercareinc.org/xw620j8qa #Dockerfile文件内容如下 #当前docker所处于的环境 FROM centos:7 #镜像的创建者 MAINTAINER zhaoboya #切换工作目录 RUN mkdir /usr/local/jdk8docker # 把jdk放入容器中 ADD jdk-8u181-linux-x64.tar.gz /usr/local/jdk8docker/ # 配置JAVA环境 ENV JAVA_HOME /usr/local/jdk8docker/jdk1.8.0_181 ENV JRE_HOME ${JAVA_HOME}/jre ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib ENV PATH ${JAVA_HOME}/bin:$PATH

Bulk Order Cbd Oil 4、构建jdk8的镜像(注意后面的“.”)

docker build -t='jdk-8u181' .

https://www.davesarcade.com/2019/09/13/ylng0al 5、测试

http://turningpointacupuncture.com/?gj6=53mj4j74 docker images

Order Cbd Vape Tablets 可以看到images中已经存在jdk的镜像

http://ozdare.com/drqu4rls 6、运行容器

docker run -d -it jdk-8u181 /bin/bash

完成!

Buy Cbd Oil Pill 1、获取私有仓库镜像

http://www.anrc-uk.com/lg08u511mln docker pull registry

http://maketodayhappy.co.uk/xlg5nm0g9 2、启动

http://www.cancercareinc.org/8olgdb9k7s 39.96.xxx.xxx:5000/v2/_catalog

Order Cbd Oil Fot 3、测试:

https://www.sdepa.fr/non-classe/nzt0bqnmv9 4、信任私有仓库 ( 修改配置文件 vim /etc/docker/daemon.json)

https://www.mansmith.com/8m6w34od9c 5、重启docker

http://champspublichealth.com/f424xply systemctl restart docker

完成!

1、打Tag标签
docker tag jdk1.8 192.168.2.129:5000/jdk1.8

1、启动私有仓库

docker start registry

2、打Tag标签

docker tag jdk-8u181 39.96.xxx.xxx:5000/jdk-8u181

3、上传

docker push 39.96.xxx.xxx:5000/jdk-8u181

4、查看

http://39.93.xxx.xxx:5000/v2/_catalog

可以看到docker仓库中已经存在了jdk-8u181

完成!

1、修改配置: docker的核心配置/属性,默认不允许三方软件(maven) ;如果要通过maven自动构建docker,需要修改权限。

修改权限配置文件

vim /lib/systemd/system/docker.service
添加如下代码到图上红色框位置
-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

2、修改完权限后,重启:

systemctl daemon-reload
systemctl restart docker

3、 要打包并上传到私有docker库 的项目 (MavenProject_eureka 上传到 私有docker库)先修改MavenProject_eureka/pom.xml 文件,添加如下配置

   <!--通过maven构建docker镜像 (刚才手工 jdk->docker;现在通过maven自动将 某个项目->docker) -->
    <build>
        <finalName>MavenProject_Eureka</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!-- 以下configuration 解决 maven一个bug:no main manifest attribute-->
                <configuration>
                    <!-- 指定该Main Class为全局的唯一入口 -->
                    <mainClass>com.zby.eureka.EurekaApplication</mainClass>
                    <layout>ZIP</layout>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.4.13</version>
                <configuration>
                    <imageName>
                        39.96.160.110:5000/eureka:${project.version}
                    </imageName>
                    <!--docker的tag为项目版本号、latest-->
                    <baseImage>jdk-8u181</baseImage>
                    <entryPoint>["java","-jar","/${project.build.finalName}.jar"] </entryPoint>
                    <resources>
                        <rescource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </rescource>
                    </resources>
                    <dockerHost>http://39.96.160.110:2375</dockerHost>
                </configuration>
            </plugin>
        </plugins>
    </build>

注意:打包的镜像名不能含有大写字母或者“_”

否则会出现如下报错:

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default-cli) on project MavenProject_Eureka: Exception caught: Requ
est error: POST http://39.96.160.110:2375/build?t=39.96.160.110:5000/MavenProject_Eureka:1.0-SNAPSHOT: 500: HTTP 500 Internal Server Error -> [H
elp 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

4、通过命令执行,自动将eureka构建成docker并上传到 私有docker仓库

mvn clean package docker:build -DpushImage  

打包上传docker完成!

5、验证

http://39.96.xxx.xxx:5000/v2/_catalog

6、查看

docker images  查看eureka的镜像是否存在

7、拉取并启动启动eureka服务

docker run -d --name=eureka -p 9999:9999  39.96.160.110:5000/eureka:1.0-SNAPSHOT

8、访问微服务端口查看相关服务是否启动

启动成功!

完成!

遇到的问题:

启动后访问不到eureka地址,使用:

systemctl status docker.service -l

查看docker启动信息,如果出现

no main manifest attribute, in /MavenProject_Eureka.jar(如图)

https://www.hackshed.co.uk/rsave6t 解决方案:

在pom中加入:

相关代码如下:

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!-- 以下configuration 解决 maven一个bug:no main manifest attribute-->
                <configuration>
                    <!-- 指定该Main Class为全局的唯一入口 -->
                    <mainClass>com.zby.eureka.EurekaApplication</mainClass>
                    <layout>ZIP</layout>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

其实在前面写的pom文件内容已经是正确的了,这里只是再强调一下

You may also like...

1 Response

  1. buy cialis说道:

    Hi colleagues, nice article and good arguments commented at this place,
    I am actually enjoying by these.

发表评论

电子邮件地址不会被公开。 必填项已用*标注