spring boot+spring cloud 集成docker基本文件配置

1. 在pom.xml中加入依赖插件,配置dockerfile文件位置,生成docker镜像的名字,要往哪个ip上发布镜像,构建的jar包的名字

<build>
<finalName>web</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<dockerHost>http://IP地址:端口号</dockerHost>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>

2.在配置好的dockerfile文件设置一些镜像基本信息,需要的基础镜像,把jar包挂载到哪个目录下,时区,非阻塞发生器等。

FROM livingobjects/jre8

VOLUME /tmp

ADD web.jar web.jar

ENV TZ=Asia/Shanghai

ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/web.jar"]

3. docker-compose文件放到root目录下,打docker-composeup -d 指令启动所有镜像

配置启动的微服务名、要暴露的端口号、时区、link关系等

version: "3"

services:

 eureka:

   image: eureka

   ports:

     - 8761:8761

   volumes:

     - /etc/localtime:/etc/localtime:ro

   environment:

     - TZ=Asia/Shanghai

  web:

   image: web

   ports:

     - 8000:8000

   links:

     - eureka

   volumes:

     - /etc/localtime:/etc/localtime:ro

   environment:

     - TZ=Asia/Shanghai

  web-ui:

   image: web-ui

   ports:

     - 8001:8001

   links:

     - eureka

   volumes:

     - /etc/localtime:/etc/localtime:ro

   environment:

     - TZ=Asia/Shanghai

 

阅读更多
文章标签: docker
下一篇Caused by: java.lang.UnsupportedOperationException: null
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭