Why does my container running `yarn run start` exit 1 seemingly at random

Viewed 33

I can't figure out why my container keeps exiting.

This is the dockerfile:

FROM node:12.22.2-alpine as base-website

RUN apk add g++ make python bash
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

ENV PATH /home/node_modules/.bin:$PATH
WORKDIR /home

FROM base-website as deps-website

COPY package.json yarn.lock ./
RUN yarn install --pure-lockfile

FROM deps-website as build-stage

COPY . .

RUN yarn run build

FROM nginx:1.23 as static-server

COPY --from=build-stage /home/build/ /usr/share/nginx/html

This is the docker-compose file

services:
  website:
    tty: true
    stdin_open: true
    build:
      context: .
    env_file: .env
    ports:
      - "4000:80"
    networks:
      - postnet

networks:
  postnet:
    name: post-net

This is the docker-compose-override

services:
  website:
    build:
      context: .
      target: build-stage
    volumes:
      - ./src:/home/src
      - ./public:/home/public
    ports:
      - "3000:3000"
    command: yarn run start

This is the output of docker compose up

[+] Running 1/1
 ⠿ Container website-frontend-website-1  Recreated                                                                                                                                                      0.1s
Attaching to website-frontend-website-1
yarn run v1.22.5
$ react-scripts start && watch-scss
website-frontend-website-1  | (node:36) [DEP0131] DeprecationWarning: The legacy HTTP parser is deprecated.
website-frontend-website-1  | [HPM] Proxy created: /  -> http://coreapi:8000
website-frontend-website-1  |
Starting the development server...
website-frontend-website-1  |
website-frontend-website-1  | Browserslist: caniuse-lite is outdated. Please run:
website-frontend-website-1  |   npx browserslist@latest --update-db
website-frontend-website-1  |   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
website-frontend-website-1 exited with code 1

Except sometimes it gets further!

13:24:16 /Users/me/dev/website-frontend/ docker compose up
[+] Running 1/1
 ⠿ Container website-frontend-website-1  Recreated                                                                                                                                                      0.1s
Attaching to website-frontend-website-1
yarn run v1.22.5
$ react-scripts start && watch-scss
website-frontend-website-1  | (node:36) [DEP0131] DeprecationWarning: The legacy HTTP parser is deprecated.
website-frontend-website-1  | [HPM] Proxy created: /  -> http://coreapi:8000
website-frontend-website-1  |
Starting the development server...
website-frontend-website-1  |
website-frontend-website-1  | Browserslist: caniuse-lite is outdated. Please run:
website-frontend-website-1  |   npx browserslist@latest --update-db
website-frontend-website-1  |   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
website-frontend-website-1  |
Compiled successfully!
website-frontend-website-1  |
website-frontend-website-1  | You can now view client in the browser.
website-frontend-website-1  |
website-frontend-website-1  |   Local:            http://localhost:3000/
website-frontend-website-1  |   On Your Network:  http://172.22.0.4:3000/
website-frontend-website-1  |
website-frontend-website-1  | Note that the development build is not optimized.
website-frontend-website-1  | To create a production build, use yarn build.
website-frontend-website-1  |

And then it happily serves my site. Until it doesn't. And it exits 1 as this: website-frontend-website-1 exited with code 1

This is what top says is running in the container (before it exits)

Mem: 7261804K used, 777988K free, 350092K shrd, 1226512K buff, 3279824K cached
CPU:   0% usr   0% sys   0% nic 100% idle   0% io   0% irq   0% sirq
Load average: 0.43 0.70 0.70 6/684 99
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
   36    29 root     S     937m  12%   1   0% /usr/local/bin/node /home/node_modules/react-scripts/scripts/start.js
   47    36 root     R     679m   9%   1   0% /usr/local/bin/node --max-old-space-size=2048 /home/node_modules/fork-ts-checker-webpack-plugin/lib/service.js
    1     0 root     S     281m   4%   0   0% node /opt/yarn-v1.22.5/bin/yarn.js run start
   29    28 root     S     216m   3%   0   0% /usr/local/bin/node /home/node_modules/.bin/react-scripts start
   91     0 root     S     2620   0%   4   0% /bin/bash
   28     1 root     S     2484   0%   1   0% /bin/sh -c react-scripts start && watch-scss
   99    91 root     R     1644   0%   3   0% top

Docker logs are not informative:

13:26:49 /Users/me/dev/website-frontend/ docker logs website-frontend-website-1
1660757206514 ready

package.json for scripts has "start": "react-scripts start && watch-scss", react-scripts is on "react-scripts": "^2.1.8",

Host machine is a Macbook Pro on Monterey 12.3, M1 Max, 32gb ram.

Docker version:

docker --version
Docker version 20.10.17, build 100c701

I really have no idea why the container is exiting. If I change it from yarn run start to just tail -f package.json then it still crashes eventually.

14:05:02 /Users/me/dev/website-frontend/ docker compose up
[+] Running 1/1
 ⠿ Container website-frontend-website-1  Recreated                                                                                                                                                      0.1s
Attaching to website-frontend-website-1
website-frontend-website-1  |     "format-code": "prettier-eslint --write 'src/**/*.{js,jsx,ts,tsx}' ",
website-frontend-website-1  |     "format-styles": "stylelint --fix 'src/**/*.scss' "
website-frontend-website-1  |   },
website-frontend-website-1  |   "browserslist": [
website-frontend-website-1  |     ">0.2%",
website-frontend-website-1  |     "not dead",
website-frontend-website-1  |     "not ie <= 11",
website-frontend-website-1  |     "not op_mini all"
website-frontend-website-1  |   ]
website-frontend-website-1  | }
a365213ea947_website-frontend-website-1 exited with code 137

Docker desktop says it has 5 CPUs allocated and 8 GB of memory.

How can I figure this out?

0 Answers
Related