Self-hosting n8n with Docker: complete setup guide
This page may contain affiliate links.
Ever felt limited by the 'free' tier of automation tools, or worried about your data being on someone else's server? If you're running a digital side hustle, efficiency is key, and having a powerful, flexible automation platform like n8n at your fingertips can be a game-changer. While n8n offers a cloud service, self-hosting gives you ultimate control, scalability, and often, significant cost savings in the long run. And the best part? With Docker, it's surprisingly straightforward, even for those who aren't seasoned server admins.
This comprehensive guide will walk you through setting up n8n on your own server using Docker and Docker Compose. We'll cover everything from choosing your server to securing your instance with SSL, ensuring you have a robust, private automation hub for all your side hustle needs. Let's get cracking!
1. Prerequisites: What You'll Need
Before we dive into the nitty-gritty, let's gather our tools and essentials:
- A Virtual Private Server (VPS): This is your digital canvas. For n8n, a server with at least 2GB RAM and 20-30GB SSD storage is a good starting point. Popular UK-friendly options include DigitalOcean (starts around £4/month), Linode (£4.50/month), or Vultr (£4/month). Choose Ubuntu 22.04 LTS as your operating system for ease of following this guide.
- A Domain Name: You'll need a domain (e.g.,
yourautomation.com) pointing to your VPS's IP address. This is crucial for accessing n8n securely with SSL. You can get one from providers like Namecheap or GoDaddy for around £8-£15/year. - An SSH Client: To connect to your server. If you're on Windows, PuTTY is a classic choice. macOS and Linux users have SSH built into their terminal.
- Basic Linux Command Line Familiarity: Don't worry, we'll give you the exact commands, but knowing your way around a terminal slightly helps.
2. Setting Up Your Server
Once you've spun up your Ubuntu 22.04 LTS VPS, it's time for the initial setup. Connect to your server via SSH using the IP address and root password provided by your VPS provider:
ssh root@YOUR_SERVER_IP_ADDRESSUpdate and Upgrade: Always start with fresh packages.
sudo apt update && sudo apt upgrade -yCreate a New User (Optional but Recommended): Running everything as root isn't best practice. Create a new user and give them sudo privileges.
sudo adduser yourusernamesudo usermod -aG sudo yourusernameLog out of root and back in as your new user: exit then ssh yourusername@YOUR_SERVER_IP_ADDRESS.
Set up a Firewall (UFW): Essential for security. Allow SSH, HTTP, and HTTPS.
sudo ufw allow OpenSSHsudo ufw allow 'http'sudo ufw allow 'https'sudo ufw enableType 'y' and Enter when prompted.
Install Docker and Docker Compose: The heart of our self-hosting setup.
sudo apt install docker.io docker-compose -ysudo systemctl start dockersudo systemctl enable dockersudo usermod -aG docker yourusernameLog out and back in one more time (exit then ssh yourusername@YOUR_SERVER_IP_ADDRESS) for the Docker group changes to take effect. Verify Docker is running: docker ps (it should show an empty list, but no errors).
3. Configuring n8n with Docker Compose
Now for the main event: setting up n8n with Docker Compose. We'll create a docker-compose.yml file that defines our n8n service and a Caddy reverse proxy to handle SSL encryption.
Create a directory for your n8n setup and navigate into it:
mkdir n8n-setupcd n8n-setupCreate the docker-compose.yml file:
nano docker-compose.ymlPaste the following content. Remember to replace your.domain.com with your actual domain and set a strong N8N_ENCRYPTION_KEY!
version: '3.8'services: n8n: image: n8nio/n8n restart: always ports: - "5678:5678" # Internal port, Caddy will handle external access environment: - N8N_HOST=your.domain.com - N8N_PROTOCOL=https - WEBHOOK_TUNNEL_URL=https://your.domain.com/ - N8N_PORT=5678 - N8N_ENCRYPTION_KEY=YOUR_VERY_STRONG_ENCRYPTION_KEY_HERE # <span style='color:red;'>CRITICAL: Change this!</span> - GENERIC_TIMEZONE=Europe/London # Or your preferred timezone - TZ=Europe/London volumes: - n8n_data:/home/node/.n8n networks: - n8n_network caddy: image: caddy:2-alpine restart: always ports: - "80:80" - "443:443" volumes: - ./Caddyfile:/etc/caddy/Caddyfile - caddy_data:/data - caddy_config:/config networks: - n8n_networkvolumes: n8n_data: caddy_data: caddy_config:networks: n8n_network:Press Ctrl+X, then Y, then Enter to save the file.
Now, create the Caddyfile for our reverse proxy and SSL setup:
nano CaddyfilePaste the following, again, replacing your.domain.com:
your.domain.com { reverse_proxy n8n:5678 log { output stdout format json }}Save and exit (Ctrl+X, Y, Enter).
Finally, bring up your n8n and Caddy services:
docker compose up -dThis command downloads the necessary Docker images, sets up the containers, and runs them in the background. It might take a few minutes for Caddy to provision your SSL certificate from Let's Encrypt.
4. Secure Access and First Login
After a few moments, you should be able to access your n8n instance by navigating to https://your.domain.com in your web browser. Caddy will have automatically handled the SSL certificate provisioning, so your connection will be secure.
On your first visit, n8n will prompt you to create an admin user account. Choose a strong password – this is the gateway to all your automations! Once logged in, you'll be greeted by the n8n dashboard, ready to create your first workflow.
Remember to keep your server and n8n secure:
- Use strong, unique passwords.
- Regularly update your system and Docker images.
- Consider setting up two-factor authentication if your n8n instance will be exposed to multiple users.
Setting up your own n8n instance is a fantastic step towards owning your automation infrastructure. But let's be honest, building those first few workflows from scratch can sometimes feel like climbing Everest! If you're looking for a genuine shortcut to get immediate value from your new n8n setup, take a peek at our n8n Starter Workflows. These plug-and-play templates are designed to be imported in minutes, giving you a head start on common side hustle automations without the initial build hassle (from £9).
5. Keeping n8n Updated and Running Smoothly
Your self-hosted n8n isn't a 'set and forget' system, but maintenance is relatively simple with Docker.
Updating n8n: Periodically, you'll want to update n8n to get the latest features and security patches. Navigate back to your n8n-setup directory on your server and run:
docker compose pulldocker compose up -dThe pull command fetches the latest n8n image, and up -d rebuilds and restarts the container with the new image. Your data will remain intact because we used a Docker volume.
Backups: Your n8n data (workflows, credentials, settings) is stored persistently in the n8n_data Docker volume. For peace of mind, you should back this up regularly. The actual data lives on your server, typically within /var/lib/docker/volumes/n8n-setup_n8n_data/_data (replace n8n-setup with your project directory name). A simple backup strategy is to periodically copy this entire directory to a safe location:
sudo tar -czvf n8n_backup_$(date +%F).tar.gz /var/lib/docker/volumes/n8n-setup_n8n_data/_dataThen, download this archive to your local machine or an object storage service like AWS S3 or Backblaze B2.
Monitoring: To check if your containers are running, use docker ps. To see logs for troubleshooting, use docker logs n8n (or docker logs caddy). For server resource usage, htop is a great tool (install with sudo apt install htop -y).
And there you have it! A fully functional, self-hosted n8n instance, powered by Docker, ready to supercharge your digital side hustle. With your automations running securely on your own server, you gain unparalleled control and flexibility. It might seem like a lot of steps, but each one builds upon the last, providing you with a robust and cost-effective automation powerhouse. Go forth and automate, Sheddad!
How Freelancers Use AI to Win Back a Working Day Every Week
Discover how UK freelancers are using AI tools to automate admin, speed up client communication, and reclaim a full day of focused work every single week.
ChatGPT Prompts for CVs, Cover Letters and Job Applications
Stuck on your CV or cover letter? These UK-tested ChatGPT prompts will help you tailor applications, beat the ATS, and land more interviews.
AI Prompts for Meeting Notes, Minutes and Action Points
Stop drowning in meeting admin. Here are the exact AI prompts that turn messy transcripts into clean minutes and action points — tested for UK teams and side hustlers.