Reputation: 5175
I have a spring-config-sever project that I am trying to run via Docker. I can run it from the command line and my other services and browser successfully connect via:
However, if I run it via Docker, the call fails.
My config-server has a Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE=build/libs/my-config-server-0.1.0.jar
ADD ${JAR_FILE} my-config-server-0.1.0.jar
EXPOSE 8980
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/my-config-server-0.1.0.jar"]
I build via:
docker build -t my-config-server .
I am running it via:
docker run my-config-server -p 8980:8980
And then I confirm it is running via
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1cecafdf99fe my-config-server "java -Djava.securit…" 14 seconds ago Up 13 seconds 8980/tcp suspicious_brahmagupta
When I run it via Docker, the browse fails with a "ERR_CONNECTION_REFUSED" and my calling services fails with:
Could not locate PropertySource: I/O error on GET request for "http://localhost:8980/aservice/dev": Connection refused (Connection refused);
Upvotes: 1
Views: 869
Reputation: 6225
Adding full answer based on comments.
First, you have to specify -p
before image name.
docker run -p 8980:8980 my-config-server
.
Second, just configuring localhost
with host port won't make your my-service container to talk to other container. locahost
in container is within itself(not host). You will need to use appropriate docker networking model so both containers can talk to each other.
If you are on Linux, the default is Bridge
so you can configure my-config-server container ip docker inspect {containerIp-of-config-server}
as your config server endpoint.
Example if your my-config-server ip is 172.17.0.2 then endpoint is - http://172.17.0.2:8980/
spring:
cloud:
config:
uri: http://172.17.0.2:8980
Just follow the docker documentation for little bit more understanding on how networking works. https://docs.docker.com/network/network-tutorial-standalone/ https://docs.docker.com/v17.09/engine/userguide/networking/
If you want to spin up both containers using docker-compose, then you can link both containers using service name. Just follow Networking in Compose.
Upvotes: 2
Reputation: 1519
I could imagine that the application only listens on localhost, ie 127.0.0.1.
You might want to try setting the property server.address
to 0.0.0.0
.
Then port 8980 should also be available externally.
Upvotes: 0