How to Deploy n8n – Workflow Automation Engine

n8n is an open-source workflow automation platform that connects applications and automates tasks without coding. It offers a visual node-based interface for building complex workflows, supports over 400 integrations, and provides self-hosted deployment for complete data privacy. n8n enables teams to automate repetitive processes, synchronize data between services, and build custom business logic.
In this article, you will deploy n8n using Docker Compose, configure persistent storage for workflow data, and set up Traefik as a reverse proxy to securely access your n8n instance.
Prerequisites
Before you begin, you need to:
- Have access to an Ubuntu 24.04-based server as a non-root user with
sudoprivileges. - Install Docker and Docker Compose.
- Configure a domain A record pointing to your server's IP address (for example,
n8n.example.com).
Set Up the Directory Structure and Environment Variables
In this section, you prepare the required directory structure for n8n and define environment variables in a .env file.
Create the directory structure for n8n.
console$ mkdir -p ~/n8n-automation/n8n-data
This directory stores workflow definitions, credentials, and execution history.
Navigate into the
n8n-automationdirectory.console$ cd ~/n8n-automation
Set proper ownership for the n8n data directory. n8n runs as the
nodeuser (UID 1000) inside the container.console$ sudo chown -R 1000:1000 n8n-data
Create a
.envfile.console$ nano .env
Add the following variables:
iniDOMAIN=n8n.example.com LETSENCRYPT_EMAIL=admin@example.com
Replace:
n8n.example.comwith your domain.admin@example.comwith your email.
Save and close the file.
Deploy with Docker Compose
In this section, you create and deploy the Docker Compose stack that runs n8n behind Traefik. Docker Compose manages both containers, applies the environment variables from your .env file, and automatically configures HTTPS routing through Traefik.
Create a new Docker Compose manifest.
console$ nano docker-compose.yaml
Add the following content.
yamlservices: traefik: image: traefik:v3.6 container_name: traefik command: - "--providers.docker=true" - "--providers.docker.exposedbydefault=false" - "--entrypoints.web.address=:80" - "--entrypoints.websecure.address=:443" - "--entrypoints.web.http.redirections.entrypoint.to=websecure" - "--entrypoints.web.http.redirections.entrypoint.scheme=https" - "--certificatesresolvers.letsencrypt.acme.httpchallenge=true" - "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web" - "--certificatesresolvers.letsencrypt.acme.email=${LETSENCRYPT_EMAIL}" - "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json" ports: - "80:80" - "443:443" volumes: - "letsencrypt:/letsencrypt" - "/var/run/docker.sock:/var/run/docker.sock:ro" restart: unless-stopped n8n: image: n8nio/n8n:latest container_name: n8n hostname: n8n expose: - "5678" volumes: - "./n8n-data:/home/node/.n8n" environment: - N8N_HOST=${DOMAIN} - N8N_PORT=5678 - N8N_PROTOCOL=https - WEBHOOK_URL=https://${DOMAIN}/ labels: - "traefik.enable=true" - "traefik.http.routers.n8n.rule=Host(`${DOMAIN}`)" - "traefik.http.routers.n8n.entrypoints=websecure" - "traefik.http.routers.n8n.tls.certresolver=letsencrypt" - "traefik.http.services.n8n.loadbalancer.server.port=5678" restart: unless-stopped volumes: letsencrypt:
Save and close the file.
This manifest defines:
- services: Two containers collaborate to deliver the automation platform:
- traefik: Manages incoming connections, provisions SSL certificates, and directs traffic to n8n.
- n8n: Executes the workflow engine and provides the visual automation interface.
- image: Container images are retrieved from Docker Hub's official repositories.
- container_name: Static identifiers enable straightforward container management and log inspection.
- command (Traefik): Establishes Docker service discovery, configures HTTP/HTTPS listeners on ports 80 and 443, enforces HTTPS redirection, and activates Let's Encrypt certificate automation via HTTP-01 challenge.
- ports (Traefik): Publishes ports 80 and 443 for external web traffic.
- expose (n8n): Opens port 5678 for internal Docker network communication without public exposure.
- volumes:
- Local directory (
./n8n-data) persists workflow configurations, encrypted credentials, and execution logs. - Named volume
letsencryptretains SSL certificate data across restarts. - Docker socket access enables Traefik to detect running containers automatically.
- Local directory (
- environment (n8n): References the domain from the
.envfile for hostname, protocol, and webhook URL configuration. - labels (n8n): Traefik routing annotations that enable proxying, define domain-based routing, attach SSL certificates, and specify the backend service port.
- restart: unless-stopped: Guarantees automatic container recovery after failures or reboots unless manually stopped.
- services: Two containers collaborate to deliver the automation platform:
Create and start the services.
console$ docker compose up -d
Verify that the services are running.
console$ docker compose ps
Output:
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS n8n n8nio/n8n:latest "tini -- /docker-ent…" n8n 28 seconds ago Up 27 seconds 5678/tcp traefik traefik:v3.6 "/entrypoint.sh --pr…" traefik 28 seconds ago Up 27 seconds 0.0.0.0:80->80/tcp, [::]:80->80/tcp, 0.0.0.0:443->443/tcp, [::]:443->443/tcpBoth containers are running. n8n processes workflows while Traefik handles connections on ports
80and443.View the logs of the services.
console$ docker compose logs
For more information on managing a Docker Compose stack, see the How To Use Docker Compose article.
Access n8n
This section demonstrates accessing the n8n web interface and creating your initial administrator account to begin building automated workflows.
Open the n8n web interface in your browser.
https://n8n.example.comCreate an owner account by providing your email address and a secure password. This account has full administrative access to all workflows and credentials.
After account creation, the n8n dashboard displays a welcome screen.
- Click Start from scratch or use the + button at the top-left to create a new workflow.
- The workflow editor provides a node-based canvas where you can add triggers and actions.
- Click Templates in the left sidebar to explore pre-built automation examples.
Conclusion
You have successfully deployed n8n for workflow automation with HTTPS encryption. The Docker Compose configuration pairs the automation engine with an automatic SSL reverse proxy, while persistent volumes preserve your workflows and credentials through container updates. Traefik manages certificate renewal and traffic routing seamlessly. Your n8n instance is ready to connect applications, automate business processes, and execute scheduled tasks through its extensive integration library.