How to make yarn start work inside Docker image with react-scripts 3.4 and babel-loader 8.1?

Viewed 12483

I'm building a Docker image for debugging of my React application with a separate Dockerfile

FROM node:11-alpine

COPY package.json .
COPY yarn.lock .
RUN yarn install

COPY public/ ./public/
COPY src/ ./src/

EXPOSE 3000
CMD yarn run start

with package.json

{
  "name": "yarn-start-in-kubernetes",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.8.1",
    "react-dom": "^16.8.1",
    "react-scripts": "2.1.3",
    "babel-loader": "8.0.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

which starts the development server as expected when the image is used with docker run. An upgrade to

    "react-scripts": "2.1.3",
    "babel-loader": "8.0.4"

causes the setup to be no longer usable because the development server terminates:

> docker run dev
yarn run v1.15.2
$ react-scripts start
ℹ 「wds」: Project is running at http://172.17.0.2/
ℹ 「wds」: webpack output is served from 
ℹ 「wds」: Content not from webpack is served from /public
ℹ 「wds」: 404s will fallback to /
Starting the development server...

Done in 2.72s.

The docker run returns after Done in ....

I'd like to use the more up-to-date versions which work fine in production. How can I make them work in the debugging image?

The versions don't seem to affect the functioning of the development server outside Docker, i.e. yarn start works with both version combinations.

2 Answers

I was having the same issue and just added: stdin_open: true to my docker-compose.yml

Related