---
title: "Deploy n8n Self-Hosted (Docker)"
description: "Step-by-step guide to self-hosting n8n with Docker Compose. "
---
# Deploy n8n
Fair-code workflow automation tool. Easily automate tasks across different services.
⭐ 49.0k stars
📜 Sustainable Use License
🔴 Advanced
⏱ ~20 minutes
## What You'll Get
A fully working n8n instance running on your server. Your data stays on your hardware — no third-party access, no usage limits, no surprise invoices.
## Prerequisites
- A server with Docker and Docker Compose installed ([setup guide](/quick-start/choosing-a-server))
- A domain name pointed to your server (optional but recommended)
- Basic terminal access (SSH)
## The Config
Create a directory for n8n and add this `docker-compose.yml`:
```yaml
# -------------------------------------------------------------------------
# 🚀 Created and distributed by The AltStack
# 🌍 https://thealtstack.com
# -------------------------------------------------------------------------
version: '3.8'
services:
n8n:
image: n8nio/n8n:latest
container_name: n8n
restart: unless-stopped
ports:
- "5678:5678"
environment:
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=password
- N8N_HOST=localhost
- N8N_PORT=5678
- N8N_PROTOCOL=http
- NODE_ENV=production
- WEBHOOK_URL=http://localhost:5678/
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:
```
## Let's Ship It
```bash
# Create a directory
mkdir -p /opt/n8n && cd /opt/n8n
# Create the docker-compose.yml (paste the config above)
nano docker-compose.yml
# Pull images and start
docker compose up -d
# Watch the logs
docker compose logs -f
```
## Environment Variables
| Variable | Default | Required |
|---|---|---|
| `N8N_BASIC_AUTH_ACTIVE` | `true` | No |
| `N8N_BASIC_AUTH_USER` | `admin` | No |
| `N8N_BASIC_AUTH_PASSWORD` | `password` | No |
| `N8N_HOST` | `localhost` | No |
| `N8N_PORT` | `5678` | No |
| `N8N_PROTOCOL` | `http` | No |
| `NODE_ENV` | `production` | No |
| `WEBHOOK_URL` | `http://localhost:5678/` | No |
## Post-Deployment Checklist
- [ ] Service is accessible on the configured port
- [ ] Admin account created (if applicable)
- [ ] Reverse proxy configured ([Caddy guide](/concepts/reverse-proxies))
- [ ] SSL/HTTPS working
- [ ] Backup script set up ([backup guide](/concepts/backups))
- [ ] Uptime monitor added ([Uptime Kuma](/deploy/uptime-kuma))
## The "I Broke It" Section
**Container won't start?**
```bash
docker compose logs n8n | tail -50
```
**Port already in use?**
```bash
# Find what's using the port
lsof -i :PORT_NUMBER
```
**Need to start fresh?**
```bash
docker compose down -v # ⚠️ This deletes volumes/data!
docker compose up -d
```
## Going Further
- [n8n on AltStack Directory](https://thealtstack.com/alternative-to/n8n)
- [n8n Self-Hosted Guide](https://thealtstack.com/self-hosted/n8n)
- [Official Documentation](https://n8n.io)
- [GitHub Repository](https://github.com/n8n-io/n8n)