Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose stops immediately after starting react app created using create-react-app

I'm trying to create a react application by using the create-react-app tool as described here.

I want to use docker-compose to run the react application inside a docker container. I have taken the following steps:

On my machine I have created a directory call app and run a nodejs docker container:

mkdir app
docker run -it --rm -v "$(pwd)/app:/app" -w /app -p 3000:3000 node:13.10.1 bash

Inside the container I initialize my react app and start my application:

npx create-react-app .
yarn start

I can see the default react page when I open http://localhost:3000/#/ in my browser.

Next, I stop yarn start and exit the container.

On my machine I can start the react app by running the following:

docker run -it --rm -v "$(pwd)/app:/app" -w /app -p 3000:3000 node:13.10.1 yarn start

Again I can see the default react page when I open http://localhost:3000/#/ in my browser.

Next, I stop the react application by stopping the docker container.

Finally, I create the following docker-compose.yml file:

version: '3.7'
services:
    test-create-react-app:
        image: node:13.10.1
        volumes:
            - ./app:/app
        working_dir: /app
        ports:
            - 3000:3000
        command: ["yarn", "start"]

When I start the docker container using docker-compose the container starts and then immediately stops:

➜  test-create-react-app docker-compose up
Creating network "test-create-react-app_default" with the default driver
Creating test-create-react-app_test-create-react-app_1 ... done
Attaching to test-create-react-app_test-create-react-app_1
test-create-react-app_1  | yarn run v1.22.0
test-create-react-app_1  | $ react-scripts start
test-create-react-app_1  | ℹ 「wds」: Project is running at http://172.21.0.2/
test-create-react-app_1  | ℹ 「wds」: webpack output is served from 
test-create-react-app_1  | ℹ 「wds」: Content not from webpack is served from /app/public
test-create-react-app_1  | ℹ 「wds」: 404s will fallback to /
test-create-react-app_1  | Starting the development server...
test-create-react-app_1  | 
test-create-react-app_1  | Done in 1.31s.
test-create-react-app_test-create-react-app_1 exited with code 0

Can someone explain why the application stops when starting the Docker container using docker-compose?

Below some versions that might help you find the problem:

Docker version:

➜  test-create-react-app docker version
Client:
 Version:           19.03.6
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        369ce74a3c
 Built:             Fri Feb 28 23:45:43 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          19.03.6
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       369ce74a3c
  Built:            Wed Feb 19 01:06:16 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.3-0ubuntu1~18.04.1
  GitCommit:        
 runc:
  Version:          spec: 1.0.1-dev
  GitCommit:        
 docker-init:
  Version:          0.18.0
  GitCommit:

Docker compose version:

➜  test-create-react-app docker-compose version
docker-compose version 1.25.0, build 0a186604
docker-py version: 4.1.0
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

React app packages:

➜  test-create-react-app cat app/package.json
{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
like image 523
MAcabot Avatar asked Mar 22 '20 16:03

MAcabot


People also ask

Is it required to run NPX create-react-APP my app every time when you need to create a react app?

If you are concerned with the size of it, you do not need to run create-react-app every time. You can make a react project yourself quite easily and by doing so you have much more control and understanding of your project.

How do I close docker compose without stopping?

TL;DR: press ctrl+c then ctrl+d - that means, keep the ctrl key pressed, type a c, and let go of ctrl. Then the same with ctrl and d. If there's a non-shell process running, the combination is ctrl+c to interrupt it. Then you can exit the shell, or the container might exit already.

How do I force recreate docker compose?

If you want to force Compose to stop and recreate all containers, use the --force-recreate flag. If the process encounters an error, the exit code for this command is 1 . If the process is interrupted using SIGINT (ctrl + C) or SIGTERM , the containers are stopped, and the exit code is 0 .


1 Answers

Adding stdin_open: true to the docker-compose file solved the issue for me. This was suggested in the corresponding github issue.

like image 90
MAcabot Avatar answered Sep 30 '22 00:09

MAcabot