ParthPatel
ParthPatel

Reputation: 144

docker compose not starting both application

I have below folder structure for my application.

rest-api-project is running on 7070 port & react-ui-project running on 8080 port.

Dockerfile for rest-api-project

FROM java:8-jdk-alpine

COPY ./Rest-Api/target/Rest-Api-0.0.1-SNAPSHOT.jar /usr/app/

WORKDIR /usr/app

RUN sh -c 'touch Rest-Api-0.0.1-SNAPSHOT.jar'
EXPOSE 7070:7070

ENTRYPOINT ["java","-jar","Rest-Api-0.0.1-SNAPSHOT.jar"]

Dockerfile for react-ui-project

FROM node:lts-alpine as build
RUN mkdir /react-ui
WORKDIR /react-ui
COPY package.json .
RUN npm install
COPY . .
EXPOSE 8080:8080
CMD ["npm","start"]

docker-compose.yml

version: "3.0"
services:
    reactui:
        build:            
            dockerfile: Dockerfile
            context: ./react-ui-project
        ports:
            - "8080:8080"
    restapi:
        build:
            dockerfile: Dockerfile
            context: ./rest-api-project
        ports:
            - "7070:7070"

I am running docker-compose up command. Both application start normally. When I try localhost:8080 in my hose browser, I do not see react application running. But If I try with localhost:7070 then I get sample response from rest-api-project.

I could not figure out why react application on localhost:8080 is not showing up.

Upvotes: 1

Views: 543

Answers (2)

ItayB
ItayB

Reputation: 11337

In order to get access from external interfaces, you need to make sure that the host is set to "0.0.0.0" instead of "localhost" or "127.0.0.1" (which is the right way to work in a development environment for security reasons).

In other words, just ensure your app is listening on:

0.0.0.0:8080

Upvotes: 1

Greg
Greg

Reputation: 423

In the Dockerfiles, change EXPOSE 7070:7070 to EXPOSE 7070 and EXPOSE 8080:8080 to EXPOSE 8080. The port binding should be done in docker-compose (as you have) or in the run command.

Upvotes: 1

Related Questions