一: 新建一个SpringBoot-web 项目
略
在pom.xml 引入Docker maven plugin
<build>
<plugins>
...
<!-- Docker maven plugin -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.10</version>
<configuration>
<tag>${project.build.finalName}-demo</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
<!-- Docker maven plugin -->
</plugins>
</build>
二: 添加Dockerfile
在pom.xml 平级目录新建Dockerfile文件
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
ADD target/${JAR_FILE} /app.jar
#暴露端口
EXPOSE 8088
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
三:使用 DockerFile 构建镜像
执行命令:
mvn clean package dockerfile:build
查看镜像结果:
docker images
四: 运行docker镜像
执行命令:
docker run -d -p 8088:8080 --name docker-demo admol/docker-demo:docker-demo
五:查看运行结果
http://localhost:8088/hello
docker ps
命令查看运行中的容器docker logs containerid -f
六:进入容器
windows 环境下:
winpty docker exec -it containerid sh
查看进程ID
jps
跟踪GC执行情况
jstat -gccause pid 3s
退出容器命令
exit
遇到的问题
问题1:打包出现错误:
[ERROR] No plugin found for prefix ‘docker‘ in the current project and in the plugin groups...
解决办法: 修改 maven 的配置文件 settings.xml
<pluginGroups>
<pluginGroup>com.spotify</pluginGroup>
</pluginGroups>
问题2:打包出现Connection refused 错误:
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.10:build (default-cli) on project docker-demo: Could not build image: java.util.concurrent.ExecutionException: com
.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: com.spotify.docker.client.shaded.org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [localhost/127.0
.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect -> [Help 1]
解决办法: 右键运行中的docker,Settings, 勾选 Expose daemon on tcp://localhost:2375 without TLS
; 然后重启docker
[docker实战] windows下使用docker部署springboot web demo项目
原文:https://www.cnblogs.com/admol/p/12800721.html