springboot single-module project docker mirroring tutorial has stepped on a pit

Introduction: Start Baidu a lot of articles, springboot docker of the article, a little problem here, there a little problem, once open seventy-eight transfer window, only deceives out.

This blog talking about the project springboot single module package, according to my operation can be a lot less pit

Start

First, if the installation in question, see my other blog https://blog.csdn.net/wu__peng/article/details/89886686  , which has a setting must tick.

First created in the src / main docker folder, and create inside Dockerfile file , the file name should be the same , I put down this path, following a local configuration is this path, if you put elsewhere, configure it ourselves

# 基于哪个镜像
FROM java:8
# 维护者的信息
MAINTAINER pengge
# 将本地文件夹挂载到当前容器
VOLUME /tmp

# 拷贝文件到容器(pom里面什么版本,这里的版本号也要改,自己jar包打的什么名字这里就什么名字)
# 不知道jar是啥子名字的,自己研究,no bb
ADD work-1.0.8.jar app.jar
RUN bash -c 'touch /app.jar'
# 开放8081端口
EXPOSE 8081
# 配置容器启动后执行的命令(springboot打包的jar包,java -jar /app.jar命令运行)
# app.jar放在容器的根目录下面的,所以/app.jar
# 启动命令复杂的,自行修改就行了,他解析命令是把方括号里面的双引号弄起来的,
# 连到一起,每个双引号的用空格隔开
ENTRYPOINT ["java", "-jar", "/app.jar"]

 

POM file two additional plugin

 

<!--加了一个这个plugin,可以打包的时候不去运行一次,跳过Test-->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
    <configuration>
        <skipTests>true</skipTests>
    </configuration>
</plugin>
<!--打包plugin配置-->
<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>0.4.3</version>
    <configuration>
        <imageName>${project.artifactId}-${project.version}</imageName>
        <!--Dockerfile存放位置-->
        <dockerDirectory>src/main/docker</dockerDirectory>
        <resources>
            <resource>
                <targetPath>/</targetPath>
                <directory>${project.build.directory}</directory>
                <include>${project.build.finalName}.jar</include>
            </resource>
        </resources>
    </configuration>
</plugin>

It, execute the command:

mvn clean package docker:build

If you have questions, I began to see Ha articles associated with another blog, I wish you good luck old iron

 

Basically no problem, and the rest is docker images Hardy did not lay the mirror, and then log on to the cloud Ali, his image management there to teach you how to push up, logically speaking, if you use the cloud NetEase, should have,

A picture

Guess you like

Origin blog.csdn.net/wu__peng/article/details/89887498