Complete Guide: Setting Up Ubuntu 22.04 for Docker-Based Application Deployment
Running modern applications efficiently requires a solid, production-ready environment. In this guide, we walk through how to prepare an Ubuntu 22.04 LTS server for running containerized applications using Docker, along with essential tools like Node.js, npm, pnpm, and PostgreSQL.
This setup is ideal for SaaS platforms, microservices architectures, and full-stack applications.
📌 Why This Setup?
Ubuntu 22.04 LTS provides:
- Long-term stability and security updates
- Strong compatibility with cloud platforms (Azure, AWS, GCP)
- Native support for containerized workloads
Combined with Docker, this setup allows:
- Consistent deployments
- Environment isolation
- Easy scaling and maintenance
🧰 Step 1: Update the System
Before installing anything, ensure your system is up to date.
apt update && apt upgrade -y
apt install -y curl wget git unzip ca-certificates gnupg lsb-release
🐳 Step 2: Install Docker (Recommended Approach)
Docker is the backbone of modern application deployment.
Add Docker Repository
mkdir -p /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpgecho "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
> /etc/apt/sources.list.d/docker.list
Install Docker Engine
apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Enable Docker Service
systemctl enable docker
systemctl start docker
Verify Installation
docker --version
docker compose version
👤 Step 3: Enable Non-root Docker Usage
Running Docker as root is not ideal. Allow your user to run Docker commands:
usermod -aG docker $USER
newgrp docker
⚡ Step 4: Install Node.js and npm
Node.js is required for backend services and frontend builds.
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs
Verify:
node -v
npm -v
📦 Step 5: Install PNPM (Fast Package Manager)
PNPM is faster and more efficient than npm for large projects.
npm install -g pnpm
Verify:
pnpm -v
🐘 Step 6: Install PostgreSQL (Optional)
If your application uses Dockerized PostgreSQL, you can skip this.
Otherwise:
apt install -y postgresql postgresql-contrib
systemctl enable postgresql
systemctl start postgresql
Access PostgreSQL:
sudo -u postgres psql
🧪 Step 7: Validate Docker Setup
Run a test container:
docker run hello-world
If this works, your Docker environment is ready.
📁 Step 8: Deploy Your Application
Clone your application repository:
git clone https://github.com/your-repo/app.git
cd app
Run the application using Docker Compose:
docker compose up -d
Check running containers:
docker ps
🔧 Useful Docker Commands
These are essential for day-to-day operations:
docker ps
docker logs -f <container>
docker exec -it <container> bash
docker compose down
docker compose up -d --build
🔐 Step 9: Basic Server Security Setup
Install and Configure Firewall
ufw allow OpenSSH
ufw allow 80
ufw allow 443
ufw enable
🌐 Step 10: Install Nginx (Optional but Recommended)
For production deployments, use Nginx as a reverse proxy:
apt install -y nginx
This allows:
- SSL termination
- Load balancing
- Domain routing
🧠 Best Practices for Production
For scalable SaaS platforms like Onsys:
✅ Use Docker for everything:
- Application services
- Databases
- Identity services (e.g., Keycloak)
- Redis / caching layers
❌ Avoid installing services directly on VM unless:
- You need high-performance tuning
- Or using managed services (Azure DB, AWS RDS)
⚡ Final Architecture Snapshot
Your Ubuntu server is now ready with:
- Docker + Docker Compose
- Node.js + npm + pnpm
- PostgreSQL (optional)
- Secure firewall configuration
- Optional Nginx reverse proxy
This setup supports:
- Microservices
- Full-stack applications
- CI/CD deployments
- Cloud-native architectures
🚀 What’s Next?
To take this further, you can:
- Add SSL with Let’s Encrypt
- Set up CI/CD pipelines (GitLab / GitHub Actions)
- Deploy Kubernetes (AKS / self-managed)
- Configure monitoring (Prometheus + Grafana)

