gpt4 book ai didi

docker - 在 docker 工具箱中运行卷时出错

转载 作者:行者123 更新时间:2023-12-02 18:06:52 24 4
gpt4 key购买 nike

这是 docker-compose 文件,我已经将文件夹设置为由 Virtual Box VM 共享,但它仍然无法正常工作。

version: '3'
services:
postgres:
image: 'postgres:latest'
deploy:
restart_policy:
condition: on-failure
window: 15m
redis:
image: 'redis:latest'
nginx:
restart: always
build:
dockerfile: Dockerfile.dev
context: ./nginx
ports:
- '3050:80'
api:
build:
dockerfile: Dockerfile.dev
context: ./server
volumes:
- /usr/src/app/node_modules
- ./server:/usr/src/app
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
- PGUSER=postgres
- PGHOST=postgres
- PGDATABASE=postgres
- PGPASSWORD=postgres_password
- PGPORT=5432
client:
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- /usr/src/app/node_modules
- ./client:/usr/src/app
worker:
build:
dockerfile: Dockerfile.dev
context: ./worker
volumes:
- /usr/src/app/node_modules
- ./worker:/usr/src/app

我在 Windows 7 sp1 上运行它。每当我运行 docker-compose up - 我都会收到一个错误:

api_1       | npm ERR! code ENOENT
api_1 | npm ERR! syscall open
api_1 | npm ERR! path /usr/src/app/package.json
api_1 | npm ERR! errno -2
api_1 | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/
app/package.json'
api_1 | npm ERR! enoent This is related to npm not being able to find a fi
le.
api_1 | npm ERR! enoent
api_1 |
api_1 | npm ERR! A complete log of this run can be found in:
api_1 | npm ERR! /root/.npm/_logs/2020-05-28T04_06_56_121Z-debug.log
complex_api_1 exited with code 254

在此先感谢,请帮忙。我正在尝试运行 Udemy Docker 和 Kubernetes 完整指南类(class)中的斐波那契项目。 enter image description here

enter image description here

每个服务都有自己的 package.json 和其他文件。

服务器 Docker 文件:

FROM node:alpine

WORKDIR /usr/src/app
COPY package.json .
RUN npm install

COPY . .


CMD ["npm", "run", "dev"]

worker Docker 文件:

FROM node:alpine

WORKDIR /usr/src/app
COPY package.json .
RUN npm install

COPY . .

CMD ["npm", "run", "dev"]

客户端 Docker 文件:

FROM node:alpine

WORKDIR /usr/src/app
COPY package.json .
RUN npm install

COPY . .


CMD ["npm", "run", "start"]

最佳答案

如果要在容器之间共享数据

services:
client:
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- datavolume:/usr/src/app/node_modules
- ./client:/usr/src/app
worker:
build:
dockerfile: Dockerfile.dev
context: ./worker
volumes:
- datavolume:/usr/src/app/node_modules
- ./worker:/usr/src/app
volumes:
datavolume: {}

因为它看起来像你的开发者,我建议将你的工作区文件夹挂载到容器中


services:
client:
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- ./node_modules:/usr/src/app/node_modules
- ./client:/usr/src/app
worker:
build:
dockerfile: Dockerfile.dev
context: ./worker
volumes:
- ./node_modules:/usr/src/app/node_modules
- ./worker:/usr/src/app

更好的方法是将每个服务都视为一个独立的项目。他们每个人都应该拥有自己的 package.json 和 node_modules。

services:
client:
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- ./client:/usr/src/app
worker:
build:
dockerfile: Dockerfile.dev
context: ./worker
volumes:
- ./worker:/usr/src/app

在我看来,在不同目的的不同项目中使用相同的库是没有意义的。

关于docker - 在 docker 工具箱中运行卷时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62056969/

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