skip to Main Content

I am building an application based on Django/DRF as backend and Angular as frontend. Angular is to be ran by Nginx. And I want to deploy this project on DigitalOcean’s droplet using docker-compose. Here is the project’s structure:

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

Here is the content of 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;"]

And here what I have in 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

When I run docker-compose up --build locally on my machine (Ubuntu 20.04) — everything builds and runs OK — I can see the project on url 0.0.0.0 and the API on 0.0.0.0:8000. But when I do the same on DigitalOcean’s droplet – I get following error:

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

Can anybody point me what I am doing wrong? That’s my first experience with Docker and Docker-compose, as well as with DigitalOcean…

Thanks in advance!

2

Answers


  1. Chosen as BEST ANSWER

    Well, finally I could solve my problem by resizing my droplet from

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

    to

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

    After doing that the deployment went OK.


  2. Here is how I solved it:

    • Build the docker image on my machine
    • Upload it to their docker registry
    • Pull the image from within the droplet and run it
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search