Technology, Tutorial, Ubuntu

EXAMPLE PODMAN-COMPOSE YAML FILE FOR N8N ON UBUNTU SERVER

What is this?

After a grueling battle with both learning Podman and getting better with containers, Caddy, databases, etc, I finally came up with a nice podman-compose.yaml file that works well for me in a MULTI-POD / MULTI-CONTAINER environment. I wanted to share it just so that others could see how I set it up and maybe use it as a guideline. You could copy/paste it and adjust it to your needs.

Directory Comments

For the directory structure to hold this setup, if you want to copy exactly what I did, you can copy and paste this next block of commands navigate to your HOME directory and run it, it will create the same directory structure to match this compose file, with a bonus directory called ‘backups’ into which you could output your database backups later if you’d like:

mkdir .n8n && \
cd .n8n && \
mkdir postgres_data && \
mkdir n8n_data && \
mkdir backups && \
cd ~

Yaml Comments

This setup uses:

  • N8N image which depends on postgres before it initiates
  • Postgres database with a long health check to make sure it’s up before n8n fires up
  • DuckDNS subdomain so no domain purchase is required (although it’s easier if you do just buy one)
  • Caddy for the reverse proxy (can’t see that in this yaml)
  • Manually created certificates for DuckDNS (more on that here if interested)
  • Uses an internal network called ‘n8n_net’ to communicate between n8n and postgres
  • Uses an external (pre-created) network called ‘proxy_net’ that all the pods hang out on as well as the evasive caddy container. See this post to learn more about that part

Some further notes to consider / research:

  1. I added this part when a bunch of stuff was broken. I am not sure if it’s really needed. Do your own research and probably try without it first and only add it if you have connection problems like I did: user: "${UID}:${GID}"
  2. I had some problems with the database password not making it properly into the Postgres initiation. I had to manually put it in so you could try with and without the quotes around the password if you encounter this to see if it helps but if not, the following command will allow you to manually jam the password in, adjusting your credentials and container names:

podman exec -it <postgres_container_name> psql -U <POSTGRES_USER> -d <POSTGRES_DB>

Here is how it works with the setup I made here:

podman exec -it n8n_postgres psql -U n8nuser -d n8n

Then when you get the n8n=# prompt, plop this in but with the appropriate password between the single quotes:

ALTER USER n8nuser WITH PASSWORD 'new_password';

THE YAML

Enough talking about it, here it is for prime copying/pasting /adjusting as you like:

services:
  postgres:
    image: docker.io/library/postgres:15
    container_name: n8n_postgres
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U n8nuser -d n8n -h localhost -p 5432"]
      interval: 5s
      timeout: 5s
      retries: 10
      start_period: 10s
    environment:
      -  POSTGRES_USER=n8nuser
      -  POSTGRES_PASSWORD="superSecretPassword"
      -  POSTGRES_DB=n8n
    userns: keep-id
    networks:
      -  n8n_net
    volumes:
      - $HOME/.n8n/postgres_data:/var/lib/postgresql/data
  n8n:
    image: docker.io/n8nio/n8n:2.0.3
    user: "${UID}:${GID}"
    container_name: n8n_app
    restart: always
    environment:
      -  DB_TYPE=postgresdb
      -  DB_POSTGRESDB_HOST=postgres
      -  DB_POSTGRESDB_PORT=5432
      -  DB_POSTGRESDB_USER=n8nuser
      -  DB_POSTGRESDB_PASSWORD="superSecretPassword"
      -  DB_POSTGRESDB_DATABASE=n8n
      -  N8N_HOST=0.0.0.0
      -  N8N_PORT=5678
      -  N8N_EDITOR_BASE_URL=https://yourDomain.duckdns.org
      -  WEBHOOK_URL=https://yourDomain.duckdns.org
      -  N8N_PROTOCOL=https
      -  NODE_OPTIONS=--dns-result-order=ipv4first
      -  NODE_ENV=production
      -  N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
    volumes:
      -  $HOME/.n8n/n8n_data:/home/node/.n8n:z
    networks:
      -  n8n_net
      -  proxy_net
    depends_on:
      postgres:
        condition: service_healthy

networks:
  n8n_net:
    internal: true

  proxy_net:
    external: true

Farewell

I try to write annoying endings to my post but I’m uninspired this time. So see ya. All the best.

Tagged , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *