【问题标题】:Why I get this issue on DigitalOcean droplet, when deploy my project with docker-compose?为什么我在使用 docker-compose 部署我的项目时在 DigitalOcean droplet 上遇到此问题?
【发布时间】:2021-06-13 10:54:14
【问题描述】:

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

当我在我的机器 (Ubuntu 20.04) 上本地运行 docker-compose up --build 时——一切都构建并运行正常——我可以在 url 0.0.0.0 上看到项目,在 0.0.0.0:8000 上看到 API。但是当我对 DigitalOcean 的液滴执行相同操作时 - 我收到以下错误:

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 的第一次体验......

提前致谢!

【问题讨论】:

    标签: angular django-rest-framework docker-compose digital-ocean droplet


    【解决方案1】:

    好吧,我终于可以通过调整我的 droplet 的大小来解决我的问题了

    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了。

    【讨论】:

      猜你喜欢
      • 2018-03-03
      • 2020-05-29
      • 1970-01-01
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      • 2016-11-06
      • 2022-01-24
      • 1970-01-01
      相关资源
      最近更新 更多