首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dokcer-使用DigitalOcean组成卷

Dokcer-使用DigitalOcean组成卷
EN

Stack Overflow用户
提问于 2021-01-31 13:19:23
回答 1查看 137关注 0票数 0

我的docker构建可以在我的设备上运行。当我上传到digital-ocean服务器并执行"docker-compose up -d“命令时,除了”前端“,所有的容器都启动了。问题出在“卷”上,当我删除它时,一切都正常。如何解决这个问题?我需要这份财产保留下来。

代码语言:javascript
复制
frontend_1 | > test-docker@0.1.0 dev /app/client
frontend_1 | > next dev
frontend_1 |
frontend_1 | sh: 1: next: not found
frontend_1 | npm ERR! code ELIFECYCLE
frontend_1 | npm ERR! syscall spawn
frontend_1 | npm ERR! file sh
frontend_1 | npm ERR! errno ENOENT
frontend_1 | npm ERR! test-docker@0.1.0 dev: `next dev`
frontend_1 | npm ERR! spawn ENOENT
frontend_1 | npm ERR!
frontend_1 | npm ERR! Failed at the test-docker@0.1.0 dev script.
frontend_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
frontend_1 | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
frontend_1 |
frontend_1 | npm ERR! A complete log of this run can be found in:
frontend_1 | npm ERR! /root/.npm/_logs/2021-01-31T01_14_30_246Z-debug.log

docker-compose.yml:

代码语言:javascript
复制
version: "3.8"

services:
  api:
    restart: always
    ports:
    - 8081:8081
    build:
      context: ./server
      dockerfile: ./Dockerfile
    volumes:
      - ./server:/app/server
    command: npm run dev
    depends_on:
      - mongo
  frontend:
    restart: always
    ports:
      - 3000:3000
    build:
      context: ./client
      dockerfile: ./Dockerfile
    volumes:
      - ./client:/app/client
    depends_on:
      - api
  mongo:
    image: mongo
    expose:
      - 27017
    ports:
      - 27017:27017
    volumes:
      - apiDB:/data/db

volumes:
  apiDB:

version: "3.8"

services:
  api:
    restart: always
    ports:
    - 8081:8081
    build:
      context: ./server
      dockerfile: ./Dockerfile
    volumes:
      - ./server:/app/server
    command: npm run dev
    depends_on:
      - mongo
  frontend:
    restart: always
    ports:
      - 3000:3000
    build:
      context: ./client
      dockerfile: ./Dockerfile
    volumes:
      - ./client:/app/client
    depends_on:
      - api
  mongo:
    image: mongo
    expose:
      - 27017
    ports:
      - 27017:27017
    volumes:
      - apiDB:/data/db

volumes:
  apiDB:

./client/Dockerfile:

代码语言:javascript
复制
FROM node:14

RUN mkdir -p /app/client
WORKDIR /app/client

COPY . /app/client
RUN npm install

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

回答 1

Stack Overflow用户

发布于 2021-02-02 01:05:54

我不建议您使用镜像的构建上下文(例如build: context: ./client)与容器的卷挂载(例如volumes: ./client:${SOMETHING})相同,这可能是问题所在。

本地主机上的构建上下文用于构建映像,并将其COPY到映像的/app/client目录。

运行映像时,您会尝试将(以前复制到映像的)目录(/app/client)替换为快捷批处理上现在为空的目录。

如果您的Dockerfile是正确的(并且复制了本地主机的./client ),那么您可以丢弃frontendvolume挂载(因为它已经在/app/client下)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65975992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档