javascript - Docker 无法识别 package.json
问题描述
对于 docker 文件系统,我完全迷失了。在挣扎了几天并阅读了文档之后,我仍然不明白这个问题的根本原因。
最小可重现示例:
码头工人-compose.yml:
version: "3"
services:
web:
build:
context: ./webapp
dockerfile: ./Dockerfile
volumes:
- './:/webapp'
- '/webapp/node_modules'
ports:
- '3000:3000'
stdin_open: true
网络应用程序/Dockerfile:
FROM node:fermium
#COPY scripts/ /scripts
COPY ./ /rxc-voice
COPY ./package.json /rxc-voice
WORKDIR /rxc-voice
RUN npm install -q
EXPOSE 3000
CMD ["npm", "start"]
我当前的目录结构是这样的:
.
├── backend
│ ├── Dockerfile
│ └── api
├── docker-compose.yml
├── README.md
├── webapp
│ ├── Dockerfile
│ ├── etc
│ ├── init.ts
│ ├── node_modules
│ ├── package.json
│ ├── package-lock.json
│ ├── public
│ ├── README.md
│ ├── src
│ └── tsconfig.json
├── scripts # used for building in other directories
└── deploy
这将拉出此错误:
web_1 | npm ERR! code ENOENT
web_1 | npm ERR! syscall open
web_1 | npm ERR! path /rxc-voice/package.json
web_1 | npm ERR! errno -2
web_1 | npm ERR! enoent ENOENT: no such file or directory, open '/rxc-voice/package.json'
web_1 | npm ERR! enoent This is related to npm not being able to find a file.
web_1 | npm ERR! enoent
尽管应该将所有内容都复制到图像中,但尝试运行时
理想情况下,docker-compose 使用.
上下文并在 Dockerfile 中切换 pwd,但我也无法让它工作。
有趣的是,目录docker build .
内部webapp
工作正常(在修改 Dockerfile 以使用不同的目录结构做同样的事情之后。
解决方案
推荐阅读
- postgresql - 如何将逗号分隔的字符串转换为postgresql中的数组
- php - PHP:DOMDocument 和 DOMXPath 不编码特殊字符
- c++ - C++:如何使#define 与自定义类一起工作?
- python - 从星期五开始创建一周
- jwt - Loopback 4 - 生成的令牌会过期多久?- 例如:待办事项
- x86 - 了解 Intel ME(管理引擎)初始化
- c# - 如果我可以简单地修复错误,为什么还要使用 try/catch?
- docker - 如何在 Kubernetes 中部署入口方法
- python - 如何使用光标对 API 进行分页?
- python - MessageBox 未在 Python GUI 中显示正确的输出