节点V18.4.0上的Docker-Compose退出代码243

发布于 2025-02-12 21:57:18 字数 1845 浏览 1 评论 0原文

当我尝试使用docker-compose部署容器时,我会收到以下错误:

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

这仅在任何节点:18.4.0 图像。我必须使用该节点版本。

我的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

我的docker-compose

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

我的应用程序(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}`)
})

我的软件包

  "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"
  }
}

。 Docker-Compose:版本1.29.2 Docker:Docker版本20.10.12,Build 20.10.12-0ubuntu2〜20.04.1

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鸩远一方 2025-02-19 21:57:18

也许您发现了问题,但这可以帮助某人:

我使用node:Bullseye图像npm v8.13.0 ,所以我将其更新为最新版本(在我的情况下,v8.15.1)已解决。

因此,要继续将此图像与最新版本一起使用,我将其放在dockerfile中:

RUN npm install -g npm@latest

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
一场春暖 2025-02-19 21:57:18

您将卷映射到/app路径上。这将图像中该路径中的所有内容都隐藏起来,包括构建Dockerfile时安装的NPM软件包。

另外,您的端口映射与您的应用不符。您的应用在端口3000上听,因此您的应用程序应将端口3000映射到主机端口。

如果您使用此Docker-Compose文件,则可以使用。

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

然后,您可以访问http:// localhost:3000/,您将获得“ Hello World!”信息。

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.

被你宠の有点坏 2025-02-19 21:57:18

首先,在您的index.js中,您曝光端口3000 const port = 3000

但是在Docker上,您将80和3009暴露了

ports:
      - 80
      - 9009:9009

提示 - 您不必复制./package.json。,您将整个文件夹复制到容器中。

WORKDIR /app

COPY . /app

RUN npm install

EXPOSE 80

CMD npm start

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文