0
I have an application that is divided into 2 parts: Frontend and Backend. Frontend is an React JS application and backend is a Java application. This project is running on Docker, where I have 3 containers: frontend, backend and db (database). My problem is that I can’t get the frontend to send a request to the backend container. Below are the Docker configuration files:
Docker-Compose:
version: "3"
services:
db:
image: postgres:9.6
container_name: db
ports:
- "5433:5432"
environment:
- POSTGRES_PASSWORD=123
- POSTGRES_USER=postgres
- POSTGRES_DB=test
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: backend
ports:
- "8085:8085"
depends_on:
- db
frontend:
container_name: frontend
build:
context: ./frontend
dockerfile: Dockerfile
expose:
- "80"
ports:
- "80:80"
links:
- backend
depends_on:
- backend
Dockerfile frontend:
# Stage 0, "build-stage", based on Node.js, to build and compile the frontend
FROM node:8.12.0 as build-stage
WORKDIR /app
COPY package*.json /app/
RUN yarn
COPY ./ /app/
RUN yarn run build
# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
FROM nginx
RUN rm -rf /usr/share/nginx/html/*
COPY --from=build-stage /app/build/ /usr/share/nginx/html
# Copy the default nginx.conf provided by tiangolo/node-frontend
COPY --from=build-stage /app/nginx.conf /etc/nginx/conf.d/default.conf
Dockerfile backend:
FROM openjdk:8
ADD /build/libs/reurb-sj-13-11-19.jar reurb-sj-13-11-19.jar
EXPOSE 8085
ENTRYPOINT ["java", "-jar", "reurb-sj-13-11-19.jar", "--app.db.host=db"]
In the Frontend I already tried to send request to:
- localhost:8085
- 172.18.0.3:8085
- 172.18.0.3
- 0.0.0.0:8085
When I try to send the Frontend request, it is "active" for about 10 seconds and then returns with error. The strange thing is that the request does not return any status.
NOTE: I already scanned the internet and everyone talks to put EXPOSE, PORTS and LINKS (there on Docker-Compose), but still nothing works.
it is active for about 10 seconds and then returns with error. What is the error returned? You checked whether your back-end application is actually serving requests on the exposed port?
– Augusto Vasques
Oops, the error is an "err_connection_reset". And yes, the backend is listening to the requests on port 8085. Remembering that this error I can only see on the console, because in the Chrome Network tab, the request there does not illustrate any status of the action.
– Douglas Martins