Docs / Containers & Docker / Container Resource Limits: CPU and Memory

Container Resource Limits: CPU and Memory

By Admin · Mar 25, 2026 · Updated Apr 23, 2026 · 7 views · 3 min read

Managing resource-limits effectively is a crucial skill for any system administrator. This tutorial provides step-by-step instructions for cpu configuration, along with best practices for production environments.

Prerequisites

  • Docker Engine 24.0+ installed
  • A VPS running Ubuntu 22.04 or later (2GB+ RAM recommended)
  • Root or sudo access to the server

Creating the Docker Compose File

The cpu component plays a crucial role in the overall architecture. Understanding how it interacts with resource-limits will help you make better configuration decisions.


# docker-compose.yml
version: '3.8'
services:
  app:
    image: resource-limits:latest
    restart: unless-stopped
    ports:
      - "8080:8080"
    volumes:
      - app_data:/data
    environment:
      - NODE_ENV=production
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  app_data:

Make sure to restart the service after applying these changes. Some settings require a full restart rather than a reload to take effect.

Building the Container Image

Before making changes to the configuration, always create a backup of the existing files. This ensures you can quickly roll back if something goes wrong during the setup process.


# Multi-stage Dockerfile
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build

FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/index.js"]

Note that file paths may vary depending on your Linux distribution. The examples here are for Debian/Ubuntu; adjust paths accordingly for RHEL/CentOS-based systems.

Configuring Volumes and Networks

The cpu component plays a crucial role in the overall architecture. Understanding how it interacts with resource-limits will help you make better configuration decisions.


# Container management commands
docker compose up -d
docker compose logs -f app
docker compose exec app sh
docker system prune -af --volumes  # Caution: removes unused data

The output should show the service running without errors. If you see any warning messages, address them before proceeding to the next step.

Important Notes

Security should be a primary consideration when configuring resource-limits. Always use strong passwords, keep software updated, and restrict network access to only the necessary ports and IP addresses.

Managing Container Lifecycle

It's recommended to test this configuration in a staging environment before deploying to production. This helps identify potential compatibility issues and allows you to benchmark performance differences.


# docker-compose.yml
version: '3.8'
services:
  app:
    image: resource-limits:latest
    restart: unless-stopped
    ports:
      - "8080:8080"
    volumes:
      - app_data:/data
    environment:
      - NODE_ENV=production
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  app_data:

Note that file paths may vary depending on your Linux distribution. The examples here are for Debian/Ubuntu; adjust paths accordingly for RHEL/CentOS-based systems.

Conclusion

This guide covered the essential steps for working with resource-limits on a VPS environment. For more advanced configurations, refer to the official documentation. Don't hesitate to reach out to our support team if you need help with your specific setup.

Was this article helpful?