0

我正在构建一个基于 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

以下是frontendDockerfile 的内容:

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

当我docker-compose up --build在我的机器(Ubuntu 20.04)上本地运行时——一切都构建并运行正常——我可以在 url 上看到项目,0.0.0.00.0.0.0:8000. 但是当我对 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 的第一次体验……

提前致谢!

4

1 回答 1

0

好吧,最后我可以通过调整我的液滴大小来解决我的问题

1CPU / 2 GB Memory / 50 GB Disk / FRA1 - Ubuntu 20.04 (LTS) x64

2CPU / 4 GB Memory / 50 GB Disk / FRA1 - Ubuntu 20.04 (LTS) x64 .

完成之后,部署就OK了。

于 2021-06-14T06:54:52.003 回答