节点V18.4.0上的Docker-Compose退出代码243
当我尝试使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许您发现了问题,但这可以帮助某人:
我使用
node:Bullseye
图像npm v8.13.0
,所以我将其更新为最新版本(在我的情况下,v8.15.1)已解决。因此,要继续将此图像与最新版本一起使用,我将其放在
dockerfile
中:Maybe you found the problem, but this can help someone:
I was havin the same issue using
node:bullseye
image that comes withnpm 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
:您将卷映射到
/app
路径上。这将图像中该路径中的所有内容都隐藏起来,包括构建Dockerfile时安装的NPM软件包。另外,您的端口映射与您的应用不符。您的应用在端口3000上听,因此您的应用程序应将端口3000映射到主机端口。
如果您使用此Docker-Compose文件,则可以使用。
然后,您可以访问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.
Then you can go to http://localhost:3000/ and you'll get your "Hello World!" message.
首先,在您的
index.js
中,您曝光端口3000const port = 3000
。但是在Docker上,您将80和3009暴露了
提示 - 您不必
复制./package.json。
,您将整个文件夹复制到容器中。First of all, In your
index.js
you exposed port 3000const port = 3000
.But on docker you exposed 80 and 3009
A tip - you don't have to
COPY ./package.json .
, you copied the entire folder into the container.