ityouknow / blog-comments

15 stars 0 forks source link

Spring Boot 2.0(四):使用 Docker 部署 Spring Boot - 纯洁的微笑博客 #133

Open ityouknow opened 6 years ago

ityouknow commented 6 years ago

http://www.ityouknow.com/springboot/2018/03/19/spring-boot-docker.html

Docker 技术发展为微服务落地提供了更加便利的环境,使用 Docker 部署 Spring Boot 其实非常简单,这篇文章我们就来简单学习下。

xiah217 commented 6 years ago

你好,请问你是用什么工具将项目拷贝服务器中的?谢谢

ityouknow commented 6 years ago

@xiah217 什么都可以呀, ssh工具,rz等

xiah217 commented 6 years ago

@ityouknow @xiah217 什么都可以呀, ssh工具,rz等

谢谢你,博主好人,将康快乐

kakadai commented 6 years ago

winscp应该也可以吧

TanqiZhou commented 6 years ago

我想知道日志去哪里了

ityouknow commented 6 years ago

@TanqiZhou 就在容器里面

xiah217 commented 6 years ago

为什么在用mvn package docker:build构建镜像的时候一直显示 Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/3.1.1/maven-archiver-3.1.1.pom

youarepppp commented 6 years ago

你的文档应该再进一步,加入用docker-compose的部分

xiah217 commented 6 years ago

@youarepppp 你的文档应该再进一步,加入用docker-compose的部分

博主已经写了相关的,你自己找

HyggeBo7 commented 6 years ago

docker run -p 7106:7106 -t springboot/spring-boot-docker 他不会后台运行唉

ityouknow commented 6 years ago

@wubodanran 加上 -d 参数,类似下面:

docker run -d -p 7106:7106 -t springboot/spring-boot-docker

xiah217 commented 6 years ago

博主,我写了两个不相关的项目a和b,分别已经得到对应的镜像springboot/a 和 springboot/b,为什么我只能docker run一个镜像,当运行另外一个镜像时就会把前面跑起来的镜像挤下去,端口没有冲突,谢谢你!

WinterChenS commented 6 years ago

太详细了,赞个

kely39 commented 6 years ago

mvn package docker:build时报错:

[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:17 min [INFO] Finished at: 2018-06-05T17:18:11+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project springboot-docker-demo: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException: Cannot retry request with a non-repeatable request entity: Connection reset by peer -> [Help 1]

怎么破?

gistmap commented 6 years ago

为什么是在centos中安装环境,不是用docker镜像安装。

kely39 commented 6 years ago

@gistmap 为什么是在centos中安装环境,不是用docker镜像安装。

maven和jdk都不是镜像安装的,有问题吗?

chyitboy commented 6 years ago

docker 安装mysql其他机器访问没问题,部署到本机就不行了,这么咋搞

kely39 commented 6 years ago

我的也没成功之后还没去跟踪了,你的maven是镜像安装的吗?

在 2018年6月29日,00:55,王小伟 notifications@github.com 写道:

您好,我按照您的教程来学习的,当执行到 mvn package docker:build 这个步骤时, 其中第三步拷贝文件时发生了错误。 Step 3/4 : ADD spring-boot-docker-1.0.jar app.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 47.904 s [INFO] Finished at: 2018-06-28T12:13:26+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project springboot-docker: Exception caught: ADD failed: stat /var/lib/docker/tmp/docker-builder804713190/spring-boot-docker-1.0.jar: no such file or directory -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 我已经把我运行的代码上传到github,地址: https://github.com/huowolf/springboot/tree/master/springboot-docker。 麻烦你有时间的时候指正一下我哪里错误了,不胜感谢!!学习啦!!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

huowolf commented 6 years ago

@kely39 我的也没成功之后还没去跟踪了,你的maven是镜像安装的吗?

在 2018年6月29日,00:55,王小伟 notifications@github.com 写道:

您好,我按照您的教程来学习的,当执行到 mvn package docker:build 这个步骤时, 其中第三步拷贝文件时发生了错误。 Step 3/4 : ADD spring-boot-docker-1.0.jar app.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 47.904 s [INFO] Finished at: 2018-06-28T12:13:26+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project springboot-docker: Exception caught: ADD failed: stat /var/lib/docker/tmp/docker-builder804713190/spring-boot-docker-1.0.jar: no such file or directory -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 我已经把我运行的代码上传到github,地址: https://github.com/huowolf/springboot/tree/master/springboot-docker。 麻烦你有时间的时候指正一下我哪里错误了,不胜感谢!!学习啦!!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

你好,我已经参照本篇博文操作成功了。 Maven不是安装的docker镜像,而是直接安装在你的远程Linux服务器上的。

huowolf commented 6 years ago

@gistmap 为什么是在centos中安装环境,不是用docker镜像安装。

我的理解:因为需要在远程服务器上手动使用Maven构建docker镜像,所以需要Maven环境,而maven环境依赖于Java环境。所以Java和Maven都需要你自己安装了。

liqimoon commented 6 years ago

@huowolf

@gistmap 为什么是在centos中安装环境,不是用docker镜像安装。

我的理解:因为需要在远程服务器上手动使用Maven构建docker镜像,所以需要Maven环境,而maven环境依赖于Java环境。所以Java和Maven都需要你自己安装了。

我也参照本篇博文操作成功了。我的理解是:项目还是需要自己构建,pom中的docker-maven-plugin 只是在maven打完包后将打包后的内容利用插件中配置的参数 结合docker:build命令构建docker镜像发布到docker容器中,当容器中存在我们已经发布上去的项目时,直接运行docker run启动即可。关于项目的构建还是需要在本地构建才行,docker-maven-plugin只是当本地(本地已安装docker环境)执行docker:build时传递相关的参数。

java-aodeng commented 6 years ago

学完去装逼

lijinghao1997 commented 6 years ago

Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project huiliang: Exception caught: com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.spotify.docker.client.messages.RegistryAuth: no String-argument constructor/factory method to deserialize from String value ('swarm')

按照博主的方法进行构建,但是报了这个错误不知道有没有大神看一下

chencong-plan commented 6 years ago
[INFO] Copying /developer/repository/springboot-docker/target/springboot-0.0.1-SNAPSHOT.jar -> /developer/repository/springboot-docker/target/docker/springboot-0.0.1-SNAPSHOT.jar
[INFO] Copying src/main/docker/Dockerfile -> /developer/repository/springboot-docker/target/docker/Dockerfile
[INFO] Building image springboot/springboot
Step 1/4 : FROM openjdk:8-jdk-alpine
 ---> 5801f7d008e5
Step 2/4 : VOLUME /tmp
 ---> Using cache
 ---> d5a539e5511f
Step 3/4 : ADD spring-boot-docker-1.0.jar app.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 33.405 s
[INFO] Finished at: 2018-08-13T14:09:45+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.13:build (default-cli) on project springboot: Exception caught: lstat spring-boot-docker-1.0.jar: no such file or directory -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

我也出现异常了 在执行mvn package docker:build这一步

derkeeUser commented 6 years ago

细节可以参考这个:https://blog.csdn.net/caox_nazi/article/details/78366584

zhangdp commented 6 years ago

请问当springboot项目更新的时候如何重新部署?难道每次都要重新创建运行docker镜像吗?再比如ADD ./nginx.conf /etc/nginx/nginx.conf,当修改了./nginx.conf文件的时候如何重新生效?

cuisea commented 6 years ago

学习了

BonnieCabrera commented 6 years ago

首先要有一台linux服务器

JellyB commented 6 years ago

嗯,讲的不错!

wuqiupeng commented 6 years ago

mvn package docker:build 报异常的,把docker-maven-plugin插件版本改成0.4.11就可以了(Mac ,linux好像没问题)

damangueyu commented 6 years ago

博主 dockerfile 中 ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
java -jar /app.jar 是什么意思?

ADD springboot.jar app.jar app.jar是什么意思? 求解答

linux-chaina commented 5 years ago

请问怎么开启远程debug 启动的时候加了这个参数 docker run -e "JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n"

报错:Error: Could not find or load main class $JAVA_OPTS

siling5998 commented 5 years ago

很棒的分享

nainiu888 commented 5 years ago

@kely39 mvn package docker:build时报错:

[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:17 min [INFO] Finished at: 2018-06-05T17:18:11+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project springboot-docker-demo: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException: Cannot retry request with a non-repeatable request entity: Connection reset by peer -> [Help 1]

怎么破? 检查你的pom构建文件中标签值是否有大写字母。。无意间加了的大写字母问题排除了一个多小时。。。。

Retr007 commented 5 years ago

FROM openjdk:8-jdk-alpine 这个好像访问不了了

Retr007 commented 5 years ago

Step 1/4 : FROM openjdk:8-jdk-alpine [INFO] [ERROR] Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) [WARNING] An attempt failed, will retry 1 more times org.apache.maven.plugin.MojoExecutionException: Could not build image

被屏蔽了这是,还有别的吗?

vincent-hughes commented 5 years ago

maven 安装地址404

vincent-hughes commented 5 years ago

补充maven-3.6.0 安装地址

https://www-us.apache.org/dist/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz 
PixelFrame commented 5 years ago

在ArchLinux虚拟机里docker跑得好好的,save再import进Windows的docker就No command specified了..

xhyrzldf commented 5 years ago

@lijinghao1997 Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project huiliang: Exception caught: com.spotify.docker.client.shaded.com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.spotify.docker.client.messages.RegistryAuth: no String-argument constructor/factory method to deserialize from String value ('swarm')

按照博主的方法进行构建,但是报了这个错误不知道有没有大神看一下

将docker插件版本改为1.2.0版本

TodayIsSunShine commented 5 years ago

@damangueyu 博主 dockerfile 中 ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
java -jar /app.jar 是什么意思?

ADD springboot.jar app.jar app.jar是什么意思? 求解答

别名

TodayIsSunShine commented 5 years ago

docker部署有什么好处吗?直接执行jar不也可以吗,麻烦大佬回答下。。。

TodayIsSunShine commented 5 years ago

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.RELEASE:repackage (default) on project spring-boot-docker: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.RELEASE:repackage failed: Unable to find main class -> [Help 1] @ityouknow 大佬,这是什么错误

godchou commented 5 years ago

ADD spring-boot-docker-1.0-SNAPSHOT.jar app.jar

monkey-ppx commented 5 years ago

用了一个多小时完美搞定!嘿嘿

djh2717 commented 5 years ago

为什么要安装 Maven 和 jdk, 这些不已经存在我们构建的镜像当中了吗?

aloneDesperado commented 5 years ago

@djh2717 为什么要安装 Maven 和 jdk, 这些不已经存在我们构建的镜像当中了吗?

maven用来打包用的,jdk配置环境变量是测试项目是否能正常启动

aloneDesperado commented 5 years ago

我想问一下from 后面的基础镜像该怎么选择,我看有的直接使用centos作为基础镜像,这个和java做基础镜像有什么区别?

cmlx1218 commented 5 years ago

可以出个jenkins+docker 持续部署持续集成的教程吗?

penghui0528 commented 5 years ago

建议使用网易镜像,不然 mvn package docker:build 会出问题
Exception caught: error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/a3/a3562aa0b991a80cfe8172847c8be6dbf6e46340b759c2b782f8b8be45342717/data?verify...