Spring和Docker:localhost没有发送任何数据。
Spring和Docker:localhost没有发送任何数据。
这个问题已经在这里有了答案:
我使用Spring(Maven)构建了一个RESTful Web Service,参考了这个指南,工作得很好:
https://spring.io/guides/gs/rest-service/
现在我想在Docker容器中启动它,但遇到了问题。请看下面我的Dockerfile:
#Take the base Java image to build upon FROM openjdk:11 #Expose the container port that your application listens to outside world #In the Sample application you can find this under Application.properties EXPOSE 9090 #Add our application Jar file to the package ADD target/demo-0.0.1-SNAPSHOT.jar demo.jar # Run the application ENTRYPOINT ["java", "-jar", "demo.jar"]
我使用以下命令构建和运行:
docker build -t username/demo.jar . docker run -p 80:9090 username/demo.jar
我检查了application.properties
文件,它是空的。我不知道这里是否需要设置什么。
我该如何纠正这个问题?
admin 更改状态以发布 2023年5月21日
从在线检查不同的帖子和博客来看,问题与端口有关。默认情况下,Spring将使用8080
端口。我将其从9090
端口更改后,Dockerfile和命令都可以工作。
我找到了一篇博客,展示了不同的更改方法,但我还没有尝试: