更多配置选项查看官方信息:
https://github.com/spotify/dockerfile-maven
Dockerfile
位置和pom.xml同级的文件,名称是Dockerfile
FROM java:8
VOLUME /tmp
ADD target/${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
插件配置
插件地址 :https://github.com/spotify/dockerfile-maven
增加属性
<properties>
<java.version>1.8</java.version>
<docker.registry.url>registry.cn-beijing.aliyuncs.com</docker.registry.url>
<docker.registry.namespace>baxiang</docker.registry.namespace>
</properties>
增加插件配置
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
<repository>${docker.registry.url}/${docker.registry.namespace}/${project.artifactId}</repository>
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
</configuration>
</plugin>
配置maven
参考 https://github.com/spotify/dockerfile-maven/blob/master/docs/authentication.md
隐藏 POM 文件中的密码
maven 提供密码加密的功能,具体过程见:https://maven.apache.org/guides/mini/guide-encryption.html
配置完 ~/.m2/setting-security.xml 后,在 ~/.m2/setting.xml 找到 servers 标签,添加:
<servers>
<server>
<id>registry.cn-shanghai.aliyuncs.com</id>
<username>userName</username>
<password>{encryptedPassword}</password>
</server>
</servers>
修改 POM 文件中的配置即可
<configuration>
<repository>registry.cn-shanghai.aliyuncs.com/xxxxx/xxxxx</repository>
- <username>userName</username>
- <password>userPassword</password>
+ <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
或者使用
<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
修改maven中的conf/settings.xml文件,找到
<server>
<!--maven的pom中可以根据这个id找到这个server节点的配置,配置成dockerhub 的URL地址-->
<id>registry.cn-beijing.aliyuncs.com</id>
<!--这里是在阿里云注册的账号-->
<username>xxxx@xxx.com</username>
<!--这里是在阿里云注册的密码-->
<password>xxxx</password>
</server>
打包命令
打tag命令
mvn package dockerfile:build
推送远程
mvn dockerfile:push
问题排查 增加-X 参数
mvn clean package docker:build -X
IDEA插件
搜索插件Docker
设置中搜索Docker
修改docker p配置
sudo vim /lib/systemd/system/docker.service
修改
增加
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375
重启docker
sudo systemctl restart docker
查看2375端口是否开发
netstat -nlp|grep 2375
tcp6 0 0 :::2375 :::* LISTEN 14626/dockerd
设置连接
参考
https://www.cnblogs.com/javastack/p/14034812.html
https://spring.io/guides/topicals/spring-boot-docker/
https://spring.io/guides/gs/spring-boot-docker/
https://blog.csdn.net/u012702547/article/details/100153799