Home > Blockchain >  docker-compose exit code 243 on node v18.4.0
docker-compose exit code 243 on node v18.4.0

Time:07-05

When I try to deploy a container using docker-compose, I get the following error:

testing    | 
testing    | > [email protected] start
testing    | > npm-run-all --parallel start:server
testing    | 
testing    | 
testing    | ERROR: "start:server" exited with 243.
testing exited with code 1

This only happens on any node:18.4.0 images. I have to use that node version.

My Dockerfile:

FROM node:18.4.0-alpine3.16

WORKDIR /app

COPY ./package.json ./
COPY ./package-lock.json ./

RUN npm install
COPY . /app

EXPOSE 80

CMD npm start

My docker-compose

version: '2'
services:
  testing:
    container_name: testing
    build:
      context: .
    volumes:
      - '.:/app'
    ports:
      - 80
      - 9009:9009

My app (index.js):

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

My package.json

  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "npm-run-all --parallel start:server",
    "start:server": "nodemon .",
    "start:web": "echo web starting"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.1",
    "nodemon": "^2.0.18"
  },
  "devDependencies": {
    "npm-run-all": "^4.1.5"
  }
}

os: Ubuntu 20.04.4 LTS. docker-compose: version 1.29.2 docker: Docker version 20.10.12, build 20.10.12-0ubuntu2~20.04.1

CodePudding user response:

You have a volume mapping onto the /app path. That hides everything in that path in the image, including the npm packages you install when building your Dockerfile.

Also, your port mappings don't match your app. Your app listens on port 3000, so your should map port 3000 to a host port.

If you use this docker-compose file, it'll work.

version: '2'
services:
  testing:
    container_name: testing
    build:
      context: .
    ports:
      - 3000:3000

Then you can go to http://localhost:3000/ and you'll get your "Hello World!" message.

CodePudding user response:

First of all, In your index.js you exposed port 3000 const port = 3000.

But on docker you exposed 80 and 3009

ports:
      - 80
      - 9009:9009

A tip - you don't have to COPY ./package.json ., you copied the entire folder into the container.

WORKDIR /app

COPY . /app

RUN npm install

EXPOSE 80

CMD npm start
  • Related