gpt4 book ai didi

node.js - 在docker-compose中映射卷时获取 “npm ERR! enoent: no such file or directory”

转载 作者:行者123 更新时间:2023-12-02 21:11:44 24 4
gpt4 key购买 nike

我有一个docker-compose文件,其中包含我的应用的自定义图片和官方的mongo图片。只要我不尝试为我的应用程序映射卷,它就可以正常工作,而我正在尝试创建开发docker-compose文件。我觉得我的docker-compose.dev.yml文件中的音量设置有误。我尝试过以其他方式设置音量,但总是会出错。我不确定如何映射该卷,以便对代码所做的任何更改都将在容器中更改

以下是我的docker-compose.dev.yml文件,我的应用程序的Dockerfile和我的package.json文件。我还将包括我看到的错误

感谢您提供的任何帮助

docker-compose.dev.yml

version: "3"
services:
app:
container_name: database
restart: always
build: .
volumes:
- ./:/usr/src/app
ports:
- "8080:8080"
links:
- mongo
mongo:
container_name: mongo
image: mongo:4
ports:
- "27017:27017"

Docker文件
FROM node:10

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
COPY package*.json ./

RUN npm install

# Bundle app source into container
COPY . .

EXPOSE 8080
CMD [ "npm", "start" ]

package.json
{
"name": "database",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.16.0",
"http-errors": "~1.6.2",
"morgan": "~1.9.0",
"pug": "2.0.0-beta11"
}
}

错误即时通讯...
WARNING: Image for service app was built because it did not already exist. 
To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating mongo ... done
Creating database ... done
Attaching to mongo, database
database | npm ERR! path /usr/src/app/package.json
database | npm ERR! code ENOENT
database | npm ERR! errno -2
database | npm ERR! syscall open
database | npm ERR! enoent ENOENT: no such file or directory, open
'/usr/src/app/package.json'
database | npm ERR! enoent This is related to npm not being able to find a file.
database | npm ERR! enoent
database |
database | npm ERR! A complete log of this run can be found in:
database | npm ERR! /root/.npm/_logs/2019-01-11T17_20_49_720Z-debug.log

最佳答案

我的docker-compose.dev.yml中的卷有误

我有

- ./:/usr/src/app

它必须是
- .:/usr/src/app

关于node.js - 在docker-compose中映射卷时获取 “npm ERR! enoent: no such file or directory”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54151560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com