skip to Main Content

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

3

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. Maybe you found the problem, but this can help someone:

    I was havin the same issue using node:bullseye image that comes with npm v8.13.0, so I updated it to the latest version (v8.15.1, in my case) an it was solved.

    So, to keep using this image with the latest version, i put this in Dockerfile:

    RUN npm install -g npm@latest
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search