-1

Update 3/23: I used author's package.json, npm install on my Mac, upgrade react-scripts to 3.4.0 and Dockerfile to fix a few issues and now this version works: https://github.com/harrywang/my-flask-react-auth/tree/6e65a7deaf89244a41a7c91843f07f4756956f95 however, this does not explain why the previous version did not work.

Update 3/23: if I only replace package.json and package-lock.json at https://github.com/harrywang/my-flask-react-auth/tree/master/services/client with the authors' versions at https://gitlab.com/testdriven/flask-react-auth/-/tree/master/services%2Fclient, it will work. Don't know why.

Following the tutorial at https://testdriven.io/courses/auth-flask-react/

Docker 2.2.0.4 Desktop on Mac

My code repo is at https://github.com/harrywang/my-flask-react-auth, where you can see the Dockerfile and docker-compose.yml, you can clone and run docker-compose up -d --build to reproduce my problem.

When I run docker-compose up -d --build, the flask and database containers work well but the node container exits with error code 0 when "Starting the development server..."

One thing I noticed is that I don't see [wds] webpack related info locally on my Mac. I don't know what they are.

enter image description here

enter image description here

but when I go to /services/client and run npm start, the node server starts and works well locally.

There is no error message during the docker building process. I have spent a few hours on this and cannot figure it out. Please help!! Thanks a lot!!

However, the author's repo at https://gitlab.com/testdriven/flask-react-auth with older versions does not have this issue: enter image description here

dami.max
  • 377
  • 3
  • 17
  • please post what you see with this command `docker logs ` – Vishrant Mar 23 '20 at 03:48
  • @Vishrant same as shown in the screenshot above. Thanks. ``` $ docker logs my-flask-react-auth_client_1 > client@0.1.0 start /usr/src/app > react-scripts start ℹ 「wds」: Project is running at http://172.18.0.4/ ℹ 「wds」: webpack output is served from ℹ 「wds」: Content not from webpack is served from /usr/src/app/public ℹ 「wds」: 404s will fallback to / Starting the development server... ``` – dami.max Mar 23 '20 at 03:51
  • You are mentioning `npm start`, but I cannot identify NodeJS being installed in your [Dockerfile](https://github.com/harrywang/my-flask-react-auth/blob/master/services/users/Dockerfile). Does it make sense? – George Tseres Mar 23 '20 at 03:57
  • 1
    @GeorgeTseres thanks, but you are referring the wrong file, the correct one is: https://github.com/harrywang/my-flask-react-auth/blob/master/services/client/Dockerfile – dami.max Mar 23 '20 at 03:59
  • the docker container will live until the command execution is not complete, in your case, as soon as `CMD ["npm", "start"]` completes, the docker container exits with status `0` – Vishrant Mar 23 '20 at 04:05
  • @Vishrant I just added the author's repo - no problem with same ` CMD ["npm", "start"]` – dami.max Mar 23 '20 at 04:12
  • Not familiar with React, but here's what I did: ``` docker run -it --entrypoint sh my-flask-react-auth_client ``` Got a shell to a new container and tried to run: `npm start` This is what I got: ```bash > client@0.1.0 start /usr/src/app > react-scripts start Could not find a required file. Name: index.html Searched in: /usr/src/app/public npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! client@0.1.0 start: `react-scripts start` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the client@0.1.0 start script. ... ``` – George Tseres Mar 23 '20 at 04:34
  • https://stackoverflow.com/a/38524425/2704032 – Vishrant Mar 23 '20 at 04:40

4 Answers4

2

I had the same problem. I am currently working through the same course. I have done every exactly like written in the guide. I was able two start 2 containers, the third one (flask-react-auth_client_1) stoped with 0.

I first tried to get into the container and execute docker run -it --entrypoint sh <image> and then npm start

No problem was detected. So I did a little research.

Apparently with react-scripts@3.4.0 or react-scripts@3.4.1+ it is impossible to run in the background now without the CI flag enabled.

My fix was, to add CI=true to the docker-compose.yml under client > environment.

I go the idea from https://github.com/facebook/create-react-app/issues/8688

p1umyi
  • 21
  • 2
  • In my case, just simply add `CI=true` into npm start scrpts, in package.json: `"start": "CI=true react-scripts start",` – thinhvo0108 Aug 14 '20 at 14:37
0

It seems that the following part is missing from the client app Dockerfile:

COPY src /usr/src/app/src
COPY public /usr/src/app/public

This will copy the source folders into the Docker image. These two lines can be set above the following line in your Dockerfile.

The way you can troubleshoot such issues is by doing a docker run -it --entrypoint sh <image> to spin up a new container and get a shell to it. Then you can run the command that the server intended to run (npm start in our case). From there, you can spot errors that may not have been propagated to docker-compose. In our case, the error was the following:

react-scripts start Could not find a required file. 
Name: index.html Searched in: /usr/src/app/public
George Tseres
  • 498
  • 6
  • 19
  • Thanks! but I think https://github.com/harrywang/my-flask-react-auth/blob/de922bede7d8777724a56fa07fbb6b6670028fe7/docker-compose.yml#L38 this line takes care of copying the files. – dami.max Mar 23 '20 at 15:47
  • Seems like they are not mounted correctly though. When I used the described method, it seems that the server started correctly without exiting. – George Tseres Mar 23 '20 at 15:51
0

In my case, just simply add CI=true into npm start scrpts, in package.json:

"start": "CI=true react-scripts start",

Thank to p1umyi 's answer above

thinhvo0108
  • 2,212
  • 1
  • 13
  • 23
0

You must include command line on docker-compose.yml :

version: '3'
services: 
  redis-server:
    image: 'redis'
  node-app:
    command: npm start #this line
    build: .
    ports: 
      - "4001:8081"
Payam Khaninejad
  • 7,692
  • 6
  • 45
  • 55