简体   繁体   English

Spring 引导应用程序无法在 Docker 中运行

[英]Spring Boot application cannot run in Docker

I am building a Spring Boot application for providing some REST services and I'd like to import it in Docker.我正在构建一个 Spring 引导应用程序以提供一些 REST 服务,我想将其导入 Docker 中。 If I run my application within IntelliJ pressing the run button, I can load the endpoints correctly.如果我在 IntelliJ 中按运行按钮运行我的应用程序,我可以正确加载端点。

My app is listening on the port 8091, as my dockerfile is the following我的应用程序正在侦听端口 8091,因为我的 dockerfile 如下

FROM openjdk:11
ADD out/artifacts/web_services_main_jar/web_services.main.jar lib_image.jar
EXPOSE 8091
ENTRYPOINT ["java","-jar","lib_image.jar"]

The code for building and running the docker container is the following构建和运行 docker 容器的代码如下

docker build --build-arg JAR_FILE=out/artifacts/web_services_main_jar/web_services.main.jar -t lib_proj .

docker run -p 8090:8091 lib_proj

The problem is that when the application is running in docker and I try to load "localhost:8090/user" in a browser, chrome returns the ERR_EMPTY_RESPONSE message.问题是当应用程序在 docker 中运行并且我尝试在浏览器中加载“localhost:8090/user”时,chrome 返回 ERR_EMPTY_RESPONSE 消息。

If I open Docker and open the CLI of the container and I run如果我打开 Docker 并打开容器的 CLI 并运行

curl localhost:8091/user

even here an error is printed "curl: (7) Failed to connect to localhost port 8091: Connection refused".即使在这里打印错误“卷曲:(7)无法连接到本地主机端口8091:连接被拒绝”。 Any suggestion?有什么建议吗?

EDIT: my application.properties already specifies address and port as follows:编辑:我的 application.properties 已经指定了地址和端口,如下所示:

server.address=0.0.0.0
server.port=8091

Ok a workaround I found is to leave all the port to the default 8080. So i replaced the 8091 in the dockerfile and the 8090 in the "docker run..." command to 8080 and now it works here.好的,我发现的解决方法是将所有端口保留为默认的 8080。所以我将 dockerfile 中的 8091 和“docker run ...”命令中的 8090 替换为 8080,现在它可以在这里工作。 I assume because tomcat behind the scene only listens to this one, and I'm figuring out how to change this.我假设因为 tomcat 在幕后只听这个,我正在想办法改变这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用docker运行Spring Boot Application - Can't run Spring Boot Application with docker Spring Boot 应用程序无法使用 cmd 运行 - Spring boot application cannot run using cmd Docker 中的 Postgres 服务器无法连接到 spring 启动应用程序 - Postgres Server in Docker cannot connect to spring boot application 无法运行 Spring 引导应用程序:osboot.SpringApplication 应用程序运行失败 - Cannot run the Spring Boot application: o.s.boot.SpringApplication application run failed Spring 引导应用程序无法运行 2 个控制器的集成测试 - Spring Boot Application cannot run integration tests for 2 controllers IntelliJ Spring Boot Run无法自动加载application.yml - intellij spring boot run cannot load application.yml automatically 无法使用 java -cp 命令运行 spring 引导应用程序 - Cannot run spring boot application using java -cp command 如何使用 docker run 命令为 Spring Boot 应用程序覆盖 application.yml 中的 spring 属性? - How can you override a spring property in application.yml for a Spring Boot application using the docker run command? Spring 启动 2 应用程序在 docker-maven-plugin 触发的 docker 容器内运行时无法连接到 mysql - Spring Boot 2 app cannot connect to mysql while run inside docker container triggered by docker-maven-plugin 在 spring mvc 应用程序中运行 spring 启动应用程序 - run spring boot application in spring mvc application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM