[英]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.