Report this

What is the reason for this report?

How to Fix High CPU Usage and Random Restarts in a Dockerized Node.js App on DigitalOcean Droplet?

Posted on May 9, 2026

I have a Node.js application running inside Docker on a DigitalOcean Ubuntu droplet. The server specs are:

  • Ubuntu 22.04
  • 2 GB RAM
  • 1 vCPU
  • Docker Engine latest version
  • Nginx reverse proxy
  • PM2 inside container

The application works normally for some time, but after receiving moderate traffic (around 40–60 concurrent users), CPU usage suddenly spikes to 100%, memory usage increases rapidly, and sometimes the droplet becomes unresponsive or restarts automatically.

Symptoms

  • docker stats shows Node.js container consuming very high CPU
  • Nginx starts returning 502 Bad Gateway
  • PM2 logs show app restarting repeatedly
  • Swap memory also fills quickly
  • Occasionally SSH connection to the droplet is lost temporarily

What I Tried

  • Increased swap size from 1 GB to 2 GB
  • Enabled PM2 cluster mode
  • Added Docker memory limits
  • Restarted Docker service
  • Optimized some database queries
  • Enabled gzip in Nginx

Docker Run Command

docker run -d
–name myapp
-p 3000:3000
–memory=“1g”
–cpus=“1.0”
my-node-app

#Questions

  1. What could be causing these CPU spikes and random restarts?
  2. Is this related to Docker resource limits or Node.js memory leaks?
  3. Should I move PM2 outside the container?
  4. What is the best way to monitor and debug resource usage on a DigitalOcean droplet?
  5. Are there recommended production settings for Docker + Node.js on low-resource droplets?

Any suggestions or troubleshooting steps would be appreciated.



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!

The developer cloud

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

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Dark mode is coming soon.