0

I want to run a simple React application inside Docker. It runs well outside but when I try to run it from docker, I get the following errors and at the moment I have no clue.

custportal_1         | yarn run v1.15.2
custportal_1         | $ react-scripts start
custportal_1         | ℹ 「wds」: Project is running at http://172.24.0.12/
custportal_1         | ℹ 「wds」: webpack output is served from 
custportal_1         | ℹ 「wds」: Content not from webpack is served from /usr/src/app/public
custportal_1         | ℹ 「wds」: 404s will fallback to /
custportal_1         | Starting the development server...
custportal_1         | 
custportal_1         | Done in 2.61s.
custportal_1 exited with code 0

The application is created by create-react-app command. My Dockerfile configuration is

FROM node:11 as build-deps
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn
COPY . ./
RUN yarn build

Again the application runs well outside but breaks when called inside Docker. In docker-compose I call the container with

command: bash -c "export PORT=8081 && yarn start"

** I have nginx reverse proxy running on the background.

kta
  • 19,412
  • 7
  • 65
  • 47
  • What error are you seeing? I only see the command in the post – Hunter McMillen Apr 28 '20 at 01:41
  • Some possible duplicates https://stackoverflow.com/questions/58419110/unable-to-run-a-development-build-of-a-react-app-in-a-docker-container-using-nod – kta Apr 28 '20 at 03:44
  • Some possible duplicates https://stackoverflow.com/questions/60790440/docker-container-exiting-immediately-after-starting-when-using-npm-init-react-ap – kta Apr 28 '20 at 03:45

1 Answers1

1

Adding stdin_open: true in docker-compose solves the problem. Took hand-full of hours to get this solution. Reference github

Also I have noticed that react-script was calling the browser abruptly inside docker during start up. It's not necessary inside docker. Adding environment variable like BROWSER=none can omit this behaviour.

Happy coding..

kta
  • 19,412
  • 7
  • 65
  • 47