How to Deploy NestJS with Docker for Free

Deploy a NestJS backend to Oracle Cloud free tier with Docker. $0/month. 4 ARM cores, 24GB RAM, 200GB storage. Step-by-step from a developer running 4 production apps on it.

Learn/How to Deploy NestJS with Docker for Free
intermediate30-45 minutes

How to Deploy NestJS with Docker for Free

NestJS on Oracle Cloud free tier. $0/month. 4 cores, 24GB RAM. Production-ready.

Prerequisites

Oracle Cloud accountSSH key pairNestJS projectDocker basics

$0/Month Backend

I run 4 production NestJS backends on Oracle Cloud's free tier. Zero dollars per month. 24GB of RAM total. It handles thousands of daily active users without issues.

This isn't a trial. It's their Always Free tier — no expiration.

What You Get (Free)

  • 4 ARM Ampere A1 cores
  • 24 GB RAM
  • 200 GB block storage
  • 10 TB/month outbound data

For comparison, equivalent specs on AWS EC2 cost ~$108/month.

Prerequisites

  • Oracle Cloud account (free signup, credit card required but not charged)
  • SSH key pair
  • Docker and Docker Compose on your local machine
  • A NestJS project

Steps

1. Create an ARM Instance

Oracle Cloud Console → Compute → Create Instance:

  • Shape: VM.Standard.A1.Flex (ARM)
  • OCPUs: 2 (leave 2 for other services)
  • RAM: 12 GB (leave 12 for other services)
  • OS: Ubuntu 22.04 (Canonical)
  • Boot volume: 50 GB
  • SSH key: Upload your public key

2. Open Ports

OCI Console → Networking → Security Lists → Add ingress rules:

  • Port 80 (HTTP)
  • Port 443 (HTTPS)
  • Port 3000 (NestJS, optional for debugging)

Also open ports in Ubuntu's firewall:

ssh ubuntu@YOUR_IP
sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 443 -j ACCEPT
sudo netfilter-persistent save

3. Install Docker

sudo apt update && sudo apt install -y docker.io docker-compose
sudo usermod -aG docker ubuntu
# Log out and back in

4. Create Dockerfile

FROM node:20-slim AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-slim
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./
EXPOSE 3000
CMD ["node", "dist/main.js"]

5. Create docker-compose.yml

services:
  api:
    build: .
    ports:
      - "3000:3000"
    env_file:
      - .env
    restart: always
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
      interval: 30s
      timeout: 10s
      retries: 3

6. Deploy

# On the server
git clone your-repo
cd your-repo
cp .env.example .env  # Edit with production values
docker-compose up -d --build

7. Set Up SSL (Let's Encrypt)

Use Caddy as a reverse proxy — it handles SSL automatically:

sudo apt install -y caddy

Edit /etc/caddy/Caddyfile:

yourdomain.com {
  reverse_proxy localhost:3000
}
sudo systemctl restart caddy

Done. HTTPS is automatic.

Gotchas

  1. Oracle's "Out of capacity" error. ARM instances are popular. If creation fails, try a different availability domain or try again later.

  2. Don't forget OCI security lists. Ubuntu firewall AND OCI security lists both need the ports open. Missing either one blocks traffic.

  3. ARM architecture. Some npm packages with native binaries need ARM builds. Most popular packages support it. Check before deploying.

Related

Or let AI App Factory handle this for you.

Everything in this guide is already pre-configured in AI App Factory. 11 AI agents automate the rest.

AI App FactoryLearnHow to Deploy NestJS with Docker for Free