简体   繁体   English

连接被拒绝:访问在Docker容器中运行的Spring Boot应用程序

[英]Connection refused: accessing a spring boot application running in docker container

I have my spring boot application and mysql database running in separate docker containers. 我的Spring Boot应用程序和mysql数据库在单独的Docker容器中运行。 I am able to access server database from my host. 我可以从主机访问服务器数据库。

My application.properties for Spring boot application looks like below: 我的Spring引导应用程序的application.properties如下所示:

spring.datasource.url=jdbc:mysql://benefitsmysql:3308/benefitsmysql
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
# ====================================================================================
# = SSL Configuration
# ====================================================================================
#security.basic.enabled=false
server.port=8443
server.ssl.key-store=keystore.jks
server.ssl.key-store-password=*******
server.ssl.keyStoreType=jks
server.ssl.keyAlias=tomcatselfsigned

I am building a docker container image by using maven plugin for docker. 我正在通过使用docker的maven插件来构建docker容器映像。 My Dockerfile looks like below: 我的Dockerfile如下所示:

FROM java:8
VOLUME /tmp
ADD Benefits.jar Benefits.jar
EXPOSE 8443
RUN bash -c 'touch /Benefits.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/Benefits.jar"]

I am starting docker container for spring boot application like below: 我正在为春季启动应用程序启动docker容器,如下所示:

docker run -p 8443:8443 --name benefits --link benefitsmysql:mysql -d c794a4d0c634

and if I do docker ps -a , I get following output 如果我做docker ps -a ,我得到以下输出

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                  PORTS                    NAMES
8070c575b6dd        c794a4d0c634        "java -Djava.secur..."   2 minutes ago       Up 2 minutes            0.0.0.0:8443->8443/tcp   benefits
aa417df08b94        mysql:5.6           "docker-entrypoint..."   2 days ago          Up 2 days               0.0.0.0:3308->3306/tcp   benefitsmysql
f55a2a7ac487        hello-world         "/hello"                 2 days ago          Exited (0) 2 days ago                            gifted_lalande

Now when I access my spring boot application running inside docker container from my windows machine like https://192.168.99.103:8443/home , I get connection refused error ERR_CONNECTION_REFUSED. 现在,当我从Windows机器(如https://192.168.99.103:8443/home访问在docker容器中运行的spring boot应用程序时,出现连接拒绝错误ERR_CONNECTION_REFUSED。

What am I missing in this configuration? 我在此配置中缺少什么?

yogsma yogsma

I read your blog, and apply your solve, but docker-machine ip didn't solve my problem. 我阅读了您的博客,并提出了解决方案,但是docker-machine ip并没有解决我的问题。 Then I realize docker containers can't communicate with 127.0.0.1 and I use their container ip 然后我意识到docker容器无法与127.0.0.1通信并且我使用了它们的容器ip

docker inspect <container_id>

then find IpAddress. 然后找到IpAddress。

This ip address is solves my problem.I dont need to use docker-machine ip 这个IP地址解决了我的问题。我不需要使用docker-machine ip

暂无
暂无

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

相关问题 访问Spring Boot应用程序拒绝与docker工具箱中运行的IP 192.168.99.100连接 - Accessing Spring boot Application refused to connect with IP 192.168.99.100 running in docker tool box 连接拒绝尝试连接 spring 在 docker 启动应用程序 - Connection refused trying to connect spring boot application in docker docker容器内的spring boot引发java.net.ConnectException:连接被拒绝(连接被拒绝) - Spring boot inside docker container throws java.net.ConnectException: Connection refused (Connection refused) Spring 引导 MySQL Docker ConnectException:连接被拒绝 - Spring Boot MySQL Docker ConnectException: Connection refused 连接拒绝从 Spring 启动应用程序容器到 Rabbitmq 容器 - Connection Refused to Rabbitmq container from Spring boot app Container Spring 使用 Postgres 应用程序启动时无法在 Docker 上运行。错误:PSQLException:拒绝连接到 127.0.0.1:5432。 - Spring Boot with Postgres application not working on Docker. Error: PSQLException: Connection to 127.0.0.1:5432 refused. 应用服务器已经在docker容器中运行,无法使用postgresql dirver.Connection denied - The application server has been running in docker container could not use postgresql dirver.Connection refused docker容器中的spring boot对连接没有反应 - spring boot in docker container not reacting to connection Spring Boot docker无法连接到mysql(连接被拒绝/ createCommunicationsException) - Spring boot docker Cannot connect to mysql (Connection refused / createCommunicationsException) docker镜像中的spring boot应用程序错误连接到localhost:5433被拒绝 - spring boot app in docker image error Connection to localhost:5433 refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM