How to Set Up a Self-Hosted n8n AI Automation Using Docker on Free Google Cloud

By self-hosting n8n on Google Cloud's free tier, you can unlock unlimited automation runs, bypassing the limitations of the cloud version, while also saving £50 on subscription fees and maintaining full control over your workflows.
How to Set Up a Self-Hosted n8n AI Automation for Free on Google Cloud
How to Set Up a Self-Hosted n8n AI Automation for Free on Google Cloud

For those who are not familiar with n8n, it is a workflow automation tool that allows users to connect apps, automate tasks, and build custom integrations with no-code and low-code options.

Here are a few automation examples using n8n:

  • Lead Capture & CRM Update – Automatically collect leads from a form and add them to HubSpot or Salesforce.
  • Social Media Auto-Posting – Schedule and post content across Twitter, LinkedIn, and Instagram.
  • Email Marketing Automation – Sync new subscribers from a website to Mailchimp and send a welcome email.
  • AI-Powered Content Generation – Use OpenAI to generate text and send it to a Google Sheet or blog.
  • E-commerce Order Processing – Notify Slack when a new Shopify order is placed and update Google Sheets.
  • Customer Support Ticketing – Create a Zendesk ticket automatically when a user submits a support request.
  • Data Scraping & Reporting – Extract data from websites and generate automated reports in Notion or Google Docs.
N8N AI
Secure and AI-native workflow automation tool for technical people. Insert code when you need it. Full source code and self-host available. Try it now.

If you have not created a free VM instance from any cloud provider, refer to this Google Cloud tutorial.

1. Install Docker

The steps may differ based on the Linux distribution. For detailed instructions, refer to the Docker documentation. Below is an example for Ubuntu:

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

2. Install Docker-Compose

The example below is for Ubuntu:

sudo apt-get install docker-compose-plugin

3. DNS setup

Add A Record to route the subdomain accordingly:
[Optional] You can refer to this Hostinger Guide.

Type: A
Name: n8n (or the desired subdomain)
IP address: <IP_OF_YOUR_SERVER>

4. Create a Docker Compose file

Create a docker-compose.yml file. Paste the following in the file:

version: "3.7"

services:
  traefik:
    image: "traefik"
    restart: always
    command:
      - "--api=true"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
      - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
      - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - traefik_data:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n.tls=true
      - traefik.http.routers.n8n.entrypoints=web,websecure
      - traefik.http.routers.n8n.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
      - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n.headers.STSPreload=true
      - traefik.http.routers.n8n.middlewares=n8n@docker
    environment:
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  traefik_data:
    external: true
  n8n_data:
    external: true

5. Create .env file

Create an .env file and change it accordingly.

# The top level domain to serve from
DOMAIN_NAME=example.com

# The subdomain to serve from
SUBDOMAIN=n8n

# DOMAIN_NAME and SUBDOMAIN combined decide where n8n will be reachable from
# above example would result in: https://n8n.example.com

# Optional timezone to set which gets used by Cron-Node by default
# If not set New York time will be used
GENERIC_TIMEZONE=Europe/Berlin

# The email address to use for the SSL certificate creation
SSL_EMAIL=user@example.com

6. Create a data folder

Create the Docker volume that's defined as n8n_data. n8n will save the database file from SQLite and the encryption key in this volume.

sudo docker volume create n8n_data

Create a volume for the Traefik data, This is defined as traefik_data.

sudo docker volume create traefik_data

7. Start Docker Compose

Start n8n docker container:

sudo docker compose up -d

To stop the n8n docker container:

sudo docker compose stop

8. Done

Now your n8n will be reachable using your custom https://n8n.example.com. n8n will only be reachable using https and not using http.

Let's build an awesome AI workflow now and change your life. 🚀

About the author
Mr Tech King

Mr Tech King

Loves to spread positivity through the art of software and design.

Explore the AI Apps Universe

Subscribe for AI Productivity Tips & Daily Summarised Tech News

Explore the AI Apps Universe

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Explore the AI Apps Universe.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.