首页 > 解决方案 > Internal Tomcat REST calls to localhost from inside Docker container

问题描述

I have a dockerfile that runs a Tomcat 7 web server with two REST APIs, a PostgreSQL database, and a Django site on Apache. (I know that best practices suggest running these as separate containers, but I wanted to package the whole system as one container for usability by non-devs).

One of my REST API calls the other REST API through the endpoint http://localhost:8080/rest2/insert. However, in bridge mode in Docker, localhost refers to the host, not the container.

I have tried hardcoding the container ip 172.17.0.2 but I still get a Connection Refused error.

I assume this will be a problem for the localhost PostgreSQL connection from rest1 as well. What are my options?

Any help is much appreciated!

标签: dockertomcatdockerfile

解决方案


无论出于何种原因,该Connection Refused错误是由 Docker 内存不足引起的。我增加了内存限制,一切都很好。希望这能帮助那些在未来挣扎的人!


推荐阅读