当使用 docker-compose 部署我的项目时,为什么我会在 DigitalOcean droplet 上遇到这个问题?

问题描述

我正在构建一个基于 Django/DRF 作为后端和 Angular 作为前端的应用程序。 Angular 将由 Nginx 运行。我想使用 docker-compose 在 DigitalOcean 的 droplet 上部署这个项目。这是项目的结构:

price_comparison_tool/
├── backend
│   ├── accounts
│   ├── api
│   ├── price_tool_project
│   ├── static
│   ├── staticfiles
│   ├── db.sqlite3
│   ├── Dockerfile
│   ├── entrypoint.sh
│   ├── manage.py
│   └── requirements.txt
├── frontend
│   ├── e2e
│   ├── node_modules
│   ├── src
│   ├── angular.json
│   ├── CREDITS
│   ├── Dockerfile
│   ├── karma.conf.js
│   ├── LICENSE
│   ├── nginx.conf
│   ├── package.json
│   ├── package-lock.json
│   ├── README.md
│   ├── tsconfig.app.json
│   ├── tsconfig.json
│   ├── tsconfig.spec.json
│   └── tslint.json
└── docker-compose.yml

这是 frontend Dockerfile 的内容:

FROM node:14-alpine as build

RUN mkdir -p /usr/src/app

# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app

COPY package.json /usr/src/app
RUN npm install
COPY . /usr/src/app
RUN npm run build-prod

FROM nginx:1.17

COPY --from=build /usr/src/app/dist /usr/share/nginx/html/
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 3000
ENTRYPOINT ["nginx","-g","daemon off;"]

这里是我在 docker-compose.yml 中的内容:

version: '3.7'

services:
  api:
    build: ./backend
    ports:
      - "8000:8000"
    volumes:
      - ./backend:/code
  web:
    build: ./frontend
    volumes:
        - .:/frontend
    ports:
      - "80:80"
    depends_on:
      - api

当我在我的机器 (Ubuntu 20.04) 上本地运行 docker-compose up --build 时——一切构建和运行正常——我可以在 url 0.0.0.0 上看到项目,在 0.0.0.0:8000 上看到 API。但是当我在 DigitalOcean 的 droplet 上做同样的事情时 - 我收到以下错误:

Step 9/13 : FROM nginx:1.17
 ---> 9beeba249f3e
Step 10/13 : COPY --from=build /usr/src/app/dist/ /usr/share/nginx/html/
ERROR: Service 'web' failed to build: COPY failed: stat usr/src/app/dist/: file does not exist

谁能指出我做错了什么?这是我第一次使用 Docker 和 Docker-compose 以及 DigitalOcean...

提前致谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)