【发布时间】:2019-02-12 14:42:25
【问题描述】:
我正在尝试使用 Dockerfile 和 docker-compose 运行一个简单的反应应用程序。但是,当我运行命令 docker-compose up 时,它会失败并显示 package.json 不存在的错误。我猜 docker 卷挂载以某种方式覆盖了这个文件。
谁能告诉我任何解决方法。
Dockerfile
FROM node:alpine
WORKDIR /apps
COPY package.json .
RUN npm install
COPY . .
CMD ["npm","run","start"]
Docker-compose.yml
version: '3'
services:
react-app:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "3000:3000"
volumes:
- /apps/node_modules
- ./:/apps
输出
docker-compose up --build
Building react-app
Step 1/6 : FROM node:alpine
---> ebbf98230a82
Step 2/6 : WORKDIR /apps
---> Using cache
---> 52ab3e742158
Step 3/6 : COPY package.json .
---> Using cache
---> b88a10e48c6f
Step 4/6 : RUN npm install
---> Using cache
---> 1da097307540
Step 5/6 : COPY . .
---> Using cache
---> c748991eb661
Step 6/6 : CMD ["npm","run","start"]
---> Using cache
---> e138b3c17689
Successfully built e138b3c17689
Successfully tagged frontend_react-app:latest
Starting 86e0c20b7955_frontend_react-app_1 ... done
Attaching to 86e0c20b7955_frontend_react-app_1
86e0c20b7955_frontend_react-app_1 | npm ERR! path /apps/package.json
86e0c20b7955_frontend_react-app_1 | npm ERR! code ENOENT
86e0c20b7955_frontend_react-app_1 | npm ERR! errno -2
86e0c20b7955_frontend_react-app_1 | npm ERR! syscall open
86e0c20b7955_frontend_react-app_1 | npm ERR! enoent ENOENT: no such file or directory, open '/apps/package.json'
86e0c20b7955_frontend_react-app_1 | npm ERR! enoent This is related to npm not being able to find a file.
86e0c20b7955_frontend_react-app_1 | npm ERR! enoent
86e0c20b7955_frontend_react-app_1 |
86e0c20b7955_frontend_react-app_1 | npm ERR! A complete log of this run can be found in:
86e0c20b7955_frontend_react-app_1 | npm ERR! /root/.npm/_logs/2019-02-12T14_36_59_257Z-debug.log
86e0c20b7955_frontend_react-app_1 exited with code 254
文件夹结构
--node_modules
--package.json
--Dockerfile.dev
--Docker-compose.yml
编辑---
试图让我的应用对源代码中的更改做出反应,而无需重新构建映像。为此,我需要这个绑定挂载才能工作。
【问题讨论】:
标签: docker docker-compose docker-volume