Home > Blockchain >  Docker-compose up fails with exit code 135
Docker-compose up fails with exit code 135

Time:09-22

I'm trying to build a simple next.js app with Docker compose but it keeps failing on docker-compose build with an exit code 135. I'm running it on a Mac M1 Pro (if that is relevant).

I couldn't find any resources pointing to an exit code 135 though.

  • This is the docker-compose.yaml
version: '3'

services:
  next-app:
    image: node:18-alpine    
    volumes:
      - ./:/site
    command: >
      sh -c "npm install && npm run build && yarn start -H 0.0.0.0 -p 80"
    working_dir: /site
    ports:
      - 80:80

And the logs:

[ ] Running 1/0
 ⠿ Container next-app  Created                                                                                                       0.0s
Attaching to next-app
next-app  | 
next-app  | up to date, audited 551 packages in 3s
next-app  | 
next-app  | 114 packages are looking for funding
next-app  |   run `npm fund` for details
next-app  | 
next-app  | 5 moderate severity vulnerabilities
next-app  | 
next-app  | To address all issues (including breaking changes), run:
next-app  |   npm audit fix --force
next-app  | 
next-app  | Run `npm audit` for details.
next-app  | 
next-app  | > [email protected] build
next-app  | > next build
next-app  | 
next-app  | info  - Linting and checking validity of types...
next-app  | 
next-app  | ./pages/cloud.tsx
next-app  | 130:6  Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
next-app  | 133:6  Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
next-app  | 150:6  Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
next-app  | 
next-app  | ./pages/index.tsx
next-app  | 176:10  Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
next-app  | 
next-app  | ./components/main-content-display.tsx
next-app  | 129:6  Warning: Do not use <img>. Use Image from 'next/image' instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
next-app  | 
next-app  | info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
next-app  | info  - Creating an optimized production build...
next-app  | Bus error
next-app exited with code 135

CodePudding user response:

You did use sh commend in docker-compose which is not a good practice to use docker. You need docker-compose.yml along with Dockerfile as mentioned below.

docker-compose.yml

version: "3"
services:
  next-app:
    build: .
    ports:
      - "80:80"

in Dockerfile

FROM node:16.15.1-alpine3.16 as site

WORKDIR /usr/src/site

COPY site/ .

RUN npm install
RUN npm run build

EXPOSE 80
CMD  npm start

after this changes you just need a single command to start server.

docker-compose up --build -d

CodePudding user response:

Without knowing exactly what's in your package.json file - I would try this.

Spin up your vanilla node:18-alpine image without installing dependencies via the adjusted compose file below.

version: '3'

services:
  next-app:
    image: node:18-alpine   
    container_name: my_test_container
    volumes:
      - ./:/site
    command: >
      sh -c "tail -f /dev/null"
    working_dir: /site
    ports:
      - 80:80

The command being used here

sh -c "tail -f /dev/null"

is a popular vanilla option for keeping a container up and running when using compose (and when not executing some other command e.g,. npm start that would keep the container running otherwise).

I have also added a container_name for reference here.

Next, enter the container and try running each command in your original sh sequentially (starting with npm install). See if one of those commands is a problem.

You can enter the container (using the container_name above) via the command below to test

docker container exec -u 0 -it my_test_container bash

As an aside, at some point I would pull commands like npm install from your compose file back to a Dockerfile defining your image (here node:18-alpine) and any additional custom installs you need for your application (here contained in package.json).

  • Related