添加Dockerfile
在目录src/main/resources目录下店家Dockerfile文件:
From java
MAINTAINER "Eric"<eric.lan@qq.com>
ADD @project.build.finalName@.jar app.jar
EXPOSE 8080
CMD java -jar app.jar
maven的setting文件
<servers> <server> <id>my-docker-registry</id> <username>wanyang3</username> <password>12345678</password> <configuration> <email>wanyang3@mail.com</email> </configuration> </server> </servers>
定义Docker Registry地址
<properties> <docker.registry>127.0.0.1:50000</docker.registry> </properties>
映入插件
将${docker.registry}的属性作为imageName的前缀,imageName一定要是符合正则[a-z0-9-_.]的,否则构建不会成功
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<serverId>my-docker-registry</serverId>
<imageName>${docker.registry}/${project.groupId}/${project.artifactId}:${project.version}</imageName>
<dockerDirectory>${project.build.outputDirectory}</dockerDirectory>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
执行构建推送命令
mvn docker:build docker:push
启动容器
docker run -d -p 58080:8080 127.0.0.1/demo.msa/msa-api.hellp:1.0.0
调整Docker容器内存限制
运行时添加参数 -m 512m