How do I get my two docker containers to communicate with each other on Localhost?
I have separated out my project into a backend and a front-end. I am now trying to run both parts in separate docker containers however i get a connection refused. I tried running both on a docker network but it didn't seem to work.
Both my Dockerfiles look like
COPY ./build/libs/demo-0.0.1-SNAPSHOT.jar /usr/app/
WORKDIR /usr/app
RUN sh -c 'touch demo-0.0.1-SNAPSHOT.jar'
RUN apk add --update \
curl \
&& rm -rf /var/cache/apk/*
ENTRYPOINT ["java","-jar","demo-0.0.1-SNAPSHOT.jar"]
and the front end makes calls to the back end by
protected <T> ResponseEntity<T> getRequest(String path, Class<T> responseType) {
return restTemplate.getForEntity("http://localhost:8090/" + path, responseType);
}
but i get a
java.net.ConnectException: Connection refused (Connection refused)
I run both my container via:
docker run -p 8090:8090 -d repo/back-end
docker run -p 8080:8080 -d repo/front-end