Report this

What is the reason for this report?

Can I host a Next.js frontend, a Node.js backend, PostgreSQL, and Elasticsearch on a single DigitalOcean Droplet?

Posted on April 24, 2025

I have no experience on hosting, Could you help me to use DigitalOcean services in an effective way.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Heya,

Well, it might be a bit too much for everything but using some docker images it should be doable.

Here are some steps how to do that.

1. Create a Droplet

  • Go to DigitalOcean dashboard

  • Click “Create” → “Droplet”

  • Choose Ubuntu 24.04 (good choice, latest and stable)

  • Choose a cheap plan (like $4 or $6/month) to start

  • Add your SSH key if you have one (or use password login for now)

2. Log into Your Droplet

From your local machine:

ssh root@your_droplet_ip

3. Install Docker

Once inside the droplet, install Docker:

sudo apt update
sudo apt install docker.io -y
sudo systemctl enable docker
sudo systemctl start docker

Also install Docker Compose (helpful for multi-container apps):

sudo apt install docker-compose -y

4. Create a docker-compose.yml

In your project folder (/home/youruser/app or wherever):

version: '3.8'

services:
  postgres:
    image: postgres:14
    restart: always
    environment:
      POSTGRES_USER: youruser
      POSTGRES_PASSWORD: yourpassword
      POSTGRES_DB: yourdb
    volumes:
      - postgres-data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.11.1
    environment:
      - discovery.type=single-node
      - ES_JAVA_OPTS=-Xms512m -Xmx512m
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - elastic-data:/usr/share/elasticsearch/data
    ports:
      - "9200:9200"

  backend:
    build: ./backend
    restart: always
    env_file:
      - ./backend/.env
    depends_on:
      - postgres
      - elasticsearch
    ports:
      - "4000:4000"

  frontend:
    build: ./frontend
    restart: always
    env_file:
      - ./frontend/.env
    depends_on:
      - backend
    ports:
      - "3000:3000"

volumes:
  postgres-data:
  elastic-data:

Folder structure:

project/
├── backend/
│   ├── Dockerfile
│   └── (Node.js backend files)
├── frontend/
│   ├── Dockerfile
│   └── (Next.js frontend files)
├── docker-compose.yml

5. Example Dockerfile for backend (backend/Dockerfile)

FROM node:20

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .

CMD ["npm", "run", "start"]

Same idea for frontend (you may want npm run build then npm run start for production).


6. Start everything

From the project folder:

docker-compose up -d

Now:

  • Frontend is on http://your_droplet_ip:3000

  • Backend is on http://your_droplet_ip:4000

  • PostgreSQL at localhost:5432

  • Elasticsearch at localhost:9200


Tips for production:

  • Install Nginx and set up reverse proxy to serve frontend and backend on ports 80/443.

  • Use Certbot to get HTTPS certificates.

  • Consider volumes for data persistence (already in the compose).

  • Monitor RAM and CPU — especially Elasticsearch memory.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.