{"id":28484236,"url":"https://github.com/pkochanowicz/n8n-setup-docker","last_synced_at":"2025-06-29T17:32:58.705Z","repository":{"id":295754774,"uuid":"990398313","full_name":"pkochanowicz/n8n-setup-docker","owner":"pkochanowicz","description":"Fast, safe and smart setup for self-hosted n8n placed in a Docker container, ready to host and connect to postgresql database.","archived":false,"fork":false,"pushed_at":"2025-06-03T14:48:02.000Z","size":20,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-03T17:47:25.359Z","etag":null,"topics":["automation","bash","chatgpt","devops","docker","n8n","open-source","postgresql","self-hosted","shell","stable-diffusion","workflow-automation"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pkochanowicz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-26T04:04:03.000Z","updated_at":"2025-06-03T13:21:59.000Z","dependencies_parsed_at":"2025-05-27T08:26:03.121Z","dependency_job_id":"e97a779b-603a-45d2-8f6b-a01d6a606720","html_url":"https://github.com/pkochanowicz/n8n-setup-docker","commit_stats":null,"previous_names":["pkochanowicz/n8n-setup-docker"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/pkochanowicz/n8n-setup-docker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkochanowicz%2Fn8n-setup-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkochanowicz%2Fn8n-setup-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkochanowicz%2Fn8n-setup-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkochanowicz%2Fn8n-setup-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkochanowicz","download_url":"https://codeload.github.com/pkochanowicz/n8n-setup-docker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkochanowicz%2Fn8n-setup-docker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262637620,"owners_count":23341160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","bash","chatgpt","devops","docker","n8n","open-source","postgresql","self-hosted","shell","stable-diffusion","workflow-automation"],"created_at":"2025-06-07T22:06:36.646Z","updated_at":"2025-06-29T17:32:58.692Z","avatar_url":"https://github.com/pkochanowicz.png","language":"Shell","readme":"\u003c!-- README.md --\u003e\n```\n#   ▄▄        ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄        ▄             ▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄    ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄             ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄         ▄ ▄▄▄▄▄▄▄▄▄▄▄ \n#  ▐░░▌      ▐░▐░░░░░░░░░░░▐░░▌      ▐░▌           ▐░░░░░░░░░░▌▐░░░░░░░░░░░▐░░░░░░░░░░░▐░▌  ▐░▐░░░░░░░░░░░▐░░░░░░░░░░░▌           ▐░░░░░░░░░░░▐░░░░░░░░░░░▐░░░░░░░░░░░▐░▌       ▐░▐░░░░░░░░░░░▌\n#  ▐░▌░▌     ▐░▐░█▀▀▀▀▀▀▀█░▐░▌░▌     ▐░▌           ▐░█▀▀▀▀▀▀▀█░▐░█▀▀▀▀▀▀▀█░▐░█▀▀▀▀▀▀▀▀▀▐░▌ ▐░▌▐░█▀▀▀▀▀▀▀▀▀▐░█▀▀▀▀▀▀▀█░▌           ▐░█▀▀▀▀▀▀▀▀▀▐░█▀▀▀▀▀▀▀▀▀ ▀▀▀▀█░█▀▀▀▀▐░▌       ▐░▐░█▀▀▀▀▀▀▀█░▌\n#  ▐░▌▐░▌    ▐░▐░▌       ▐░▐░▌▐░▌    ▐░▌           ▐░▌       ▐░▐░▌       ▐░▐░▌         ▐░▌▐░▌ ▐░▌         ▐░▌       ▐░▌           ▐░▌         ▐░▌              ▐░▌    ▐░▌       ▐░▐░▌       ▐░▌\n#  ▐░▌ ▐░▌   ▐░▐░█▄▄▄▄▄▄▄█░▐░▌ ▐░▌   ▐░▌▄▄▄▄▄▄▄▄▄▄▄▐░▌       ▐░▐░▌       ▐░▐░▌         ▐░▌░▌  ▐░█▄▄▄▄▄▄▄▄▄▐░█▄▄▄▄▄▄▄█░▌▄▄▄▄▄▄▄▄▄▄▄▐░█▄▄▄▄▄▄▄▄▄▐░█▄▄▄▄▄▄▄▄▄     ▐░▌    ▐░▌       ▐░▐░█▄▄▄▄▄▄▄█░▌\n#  ▐░▌  ▐░▌  ▐░▌▐░░░░░░░░░▌▐░▌  ▐░▌  ▐░▐░░░░░░░░░░░▐░▌       ▐░▐░▌       ▐░▐░▌         ▐░░▌   ▐░░░░░░░░░░░▐░░░░░░░░░░░▐░░░░░░░░░░░▐░░░░░░░░░░░▐░░░░░░░░░░░▌    ▐░▌    ▐░▌       ▐░▐░░░░░░░░░░░▌\n#  ▐░▌   ▐░▌ ▐░▐░█▀▀▀▀▀▀▀█░▐░▌   ▐░▌ ▐░▌▀▀▀▀▀▀▀▀▀▀▀▐░▌       ▐░▐░▌       ▐░▐░▌         ▐░▌░▌  ▐░█▀▀▀▀▀▀▀▀▀▐░█▀▀▀▀█░█▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀█░▐░█▀▀▀▀▀▀▀▀▀     ▐░▌    ▐░▌       ▐░▐░█▀▀▀▀▀▀▀▀▀ \n#  ▐░▌    ▐░▌▐░▐░▌       ▐░▐░▌    ▐░▌▐░▌           ▐░▌       ▐░▐░▌       ▐░▐░▌         ▐░▌▐░▌ ▐░▌         ▐░▌     ▐░▌                       ▐░▐░▌              ▐░▌    ▐░▌       ▐░▐░▌          \n#  ▐░▌     ▐░▐░▐░█▄▄▄▄▄▄▄█░▐░▌     ▐░▐░▌           ▐░█▄▄▄▄▄▄▄█░▐░█▄▄▄▄▄▄▄█░▐░█▄▄▄▄▄▄▄▄▄▐░▌ ▐░▌▐░█▄▄▄▄▄▄▄▄▄▐░▌      ▐░▌             ▄▄▄▄▄▄▄▄▄█░▐░█▄▄▄▄▄▄▄▄▄     ▐░▌    ▐░█▄▄▄▄▄▄▄█░▐░▌          \n#  ▐░▌      ▐░░▐░░░░░░░░░░░▐░▌      ▐░░▌           ▐░░░░░░░░░░▌▐░░░░░░░░░░░▐░░░░░░░░░░░▐░▌  ▐░▐░░░░░░░░░░░▐░▌       ▐░▌           ▐░░░░░░░░░░░▐░░░░░░░░░░░▌    ▐░▌    ▐░░░░░░░░░░░▐░▌          \n#   ▀        ▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀        ▀▀             ▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀    ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀         ▀             ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀      ▀      ▀▀▀▀▀▀▀▀▀▀▀ ▀           \n#                                                                                                                                                                                              \n🌀 Seamless DevOps. Powered by Swarm, Secured by Secrets.\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"n8n\" src=\"https://img.shields.io/badge/n8n-self--hosted-brightgreen?style=for-the-badge\u0026logo=n8n\u0026logoColor=white\"\u003e\n  \u003cimg alt=\"docker\" src=\"https://img.shields.io/badge/docker-swarm-blue?style=for-the-badge\u0026logo=docker\"\u003e\n  \u003cimg alt=\"secure\" src=\"https://img.shields.io/badge/secrets-managed-critical?style=for-the-badge\u0026logo=gnuprivacyguard\u0026logoColor=white\"\u003e\n  \u003cimg alt=\"built-by\" src=\"https://img.shields.io/badge/built%20by-pkochanowicz-F54D27?style=for-the-badge\u0026logo=git\u0026logoColor=white\"\u003e\n\u003c/p\u003e\n\n---\n\n# 🔧 n8n-setup-docker: Secure, Custom, Ready for Action\n\nThis repo delivers a production-friendly `n8n` stack using:\n\n- 🐳 **Docker Swarm** for container orchestration  \n- 🔐 **Docker Secrets** for all sensitive env vars  \n- ⚙️ Custom scripts to prep, deploy, and launch cleanly  \n- 🧠 Readable, modifiable, highly hackable code  \n\nIf you want a secure, local-AND-remote deployable `n8n` instance with PostgreSQL and zero manual docker CLI poking…  \n**This is it.**\n\n---\n\n## 🧠 Project Tree\n\n```txt\n./\n├── docker-compose.yaml              # Swarm service definition\n├── Dockerfile                       # Custom n8n image with psql \u0026 logic\n├── container_run.sh                 # Entry script inside container\n├── docker_swarm_deploy.sh           # Dev’s best friend — deploys everything\n├── docker_clear_env_vars.sh         # Script to remove or unset sensitive environment variables from the shell/session.\n├── docker_destroy_container.sh      # Script to fully stop and remove Docker stack, containers, volumes, and leave Swarm.\n├── README.md                        # Project overview, usage instructions, diagrams, and badges. Your main documentation.\n├── Docker_cheatsheet.md             # Handy reference for common Docker commands tailored to your workflow.\n├── .gitignore                       # Git config file to exclude specified files/folders (like secrets, volumes, etc.) from version control.\n├── .dockerignore                    # Docker config file to exclude files/folders from being copied into Docker build context.\n├── secrets/                         # 🔥 Sensitive data here (not git-tracked!)\n│   ├── N8N_BASIC_AUTH_USER.txt\n│   ├── N8N_BASIC_AUTH_PASSWORD.txt\n│   ├── N8N_ENCRYPTION_KEY.txt\n│   ├── DB_POSTGRESDB_HOST.txt\n│   ├── DB_POSTGRESDB_PORT.txt\n│   ├── DB_POSTGRESDB_DATABASE.txt\n│   ├── DB_POSTGRESDB_SCHEMA.txt\n│   ├── DB_POSTGRESDB_USER.txt\n│   ├── DB_POSTGRESDB_PASSWORD.txt\n│   └── N8N_PORT.txt                  # optional\n```\n\n---\n\n# 🚀 Quickstart\n### 1️⃣ Initialize Docker Swarm (if needed)\n\n```bash\n# only needed on the first run:\ndocker swarm init\n```\n\n---\n\n### 2️⃣ Add Your Secrets\n\nDrop plain-text secret files into the ./secrets/ in the project dir. Example:\n\n```bash\n\necho \"admin\"    \u003e secrets/N8N_BASIC_AUTH_USER.txt\necho \"hunter2\"  \u003e secrets/N8N_BASIC_AUTH_PASSWORD.txt\necho \"myKeyBase\" \u003e secrets/N8N_ENCRYPTION_KEY.txt\n\necho \"db.example.com\" \u003e secrets/DB_POSTGRESDB_HOST.txt\necho \"public\"         \u003e secrets/DB_POSTGRESDB_SCHEMA.txt\necho \"5432\"           \u003e secrets/DB_POSTGRESDB_PORT.txt\necho \"n8n_user\"       \u003e secrets/DB_POSTGRESDB_USER.txt\necho \"pa$$w0rd\"       \u003e secrets/DB_POSTGRESDB_PASSWORD.txt\necho \"n8n\"            \u003e secrets/DB_POSTGRESDB_DATABASE.txt\n```\nAnd the same for your DB creds.\n\n---\n\n### 3️⃣ Deploy It Like a Boss\n\n```bash\n./docker_swarm_deploy.sh\n```\nThis will:\n\n    🏗️ Build your my-n8n:latest image\n\n    🔐 Create (or update) all Docker secrets\n\n    📦 Deploy a Swarm stack (n8n_stack) with those secrets\n\n    🧠 Auto-detect your timezone and inject it too!\n\n---\n\n### 4️⃣ Check Docker logs:\n\n```bash\ndocker service logs -f n8n_stack_n8n\n```\nAnd that's it - n8n is set up and ready! In case of online deployment you'll be able to access your automations from anywhere!\n(login using the values from your secret files)\n\n---\n\n## 🔍 What's Actually Happening?\n\nYour container launches via:\n`container_run.sh`:\n\n    🧪 Loads secrets from /run/secrets/…\n\n    🔁 Converts them into environment variables\n\n    ✅ Tests PostgreSQL DB connection via psql\n\n    🎬 Runs n8n ONLY if everything is healthy\n\n💡 Fail fast, fail clean — or don’t fail at all.\n\n---\n\n## ♻️ Rotating Secrets\n\nSecrets are immutable in Docker Swarm.\nTo update:\n\n```bash\n# Edit files in ./secrets/*.txt\n\n# Then:\n./docker_swarm_deploy.sh\n```\nThis deletes+recreates them automatically.\n\n---\n\n### 💾 Helpful scripts\n(mostly helpful during development, not recommended for production):\n\n#### 💥 Getting rid of Docker Containers\n\nWanna burn it down?\n\n```bash\n./docker_destroy_container.sh\n```\n(Watch out - the script stops and removes all the Docker containers!)\n\n---\n\n#### 🧼 Cleaning Up env variables\n\nIn case mess in env variables is giving you a headache:\n\n```bash\n./docker_clear_env_variables.sh\n```\n\n---\n\n#### 👽 Need to reset n8n credentials within Docker container?\n\n```bash\n# This will list running containers, localise id or name of running container with n8n:\ndocker ps\n\n# Execute n8n credentials reset command inside container:\ndocker exec -it \u003ccontainer_name_or_id\u003e n8n user-management:reset\n```\n\n---\n\n### 📘 Docker Cheatsheet\n📎 Check out the [Docker_cheatsheet.md](./Docker_cheatsheet.md) for more handy commands!\n\n#### (I see you, automation fiend 😎)\n\n---\n\n## 💪 Powered By\n\n| 🧠 Platform| 🌐 Link |\n|------------|---------|\n| 🔧 **[n8n](https://n8n.io/)** – powerful workflow automation | 🧩 [Docs](https://docs.n8n.io/) |\n| 🐳 **[Docker](https://www.docker.com/)** – containerize all the things | 📦 [Hub](https://hub.docker.com/) |\n| 🐘 **[PostgreSQL](https://www.postgresql.org/)** – battle-tested relational database | 📚 [Docs](https://www.postgresql.org/docs/) |\n| 🤖 **[ChatGPT](https://chat.openai.com/)** – natural language assistant magic ✨ | 🔍 [OpenAI](https://openai.com/chatgpt) |\n\n---\n\n## 🚀 Free Tier PostgreSQL Hosting for n8n Self-Hosting (examples):\n\n| 🏢 Service | 💸 Free Tier Highlights | 🔗 Link |\n|-----------|-------------------------|---------|\n| 🦄 **[Supabase](https://supabase.com/)** – Open-source Firebase alternative with Postgres backend, perfect for real-time \u0026 n8n integration | 🆓 500 MB storage, 2 million requests/month, 24/7 uptime, generous free tier | 🔥 [Supabase Free](https://supabase.com/pricing) |\n| ☁️ **[ElephantSQL](https://www.elephantsql.com/)** – Simple managed PostgreSQL hosting with free shared plans | 🆓 20 MB storage, easy to connect, ideal for dev \u0026 small projects | 🐘 [ElephantSQL Plans](https://www.elephantsql.com/plans.html) |\n| ☁️ **[Heroku Postgres](https://www.heroku.com/postgres)** – Classic cloud PaaS with free tier database | 🆓 1,000 rows, 20 connections, 10k rows/day writes, sleeps after inactivity (may impact response time) | 🚀 [Heroku Postgres Free](https://www.heroku.com/pricing#postgres) |\n| ☁️ **[Neon](https://neon.tech/)** – Serverless Postgres with automatic scaling and free tier | 🆓 10 GB storage, 1 million monthly requests, modern cloud-native Postgres | ⚡️ [Neon Free Tier](https://neon.tech/pricing) |\n| 🐦 **[Aiven](https://aiven.io/postgresql)** – Fully managed PostgreSQL with free trial and credits | 🎁 30-day free trial with $30 credit, easy migration \u0026 high availability | 🎉 [Aiven Free Trial](https://aiven.io/pricing) |\n| ☁️ **[Citus Data on Azure](https://azure.microsoft.com/en-us/services/postgresql/)** – Horizontal scale-out Postgres, free for dev/test | 🆓 $200 Azure credit for 30 days + free tier options | 💎 [Azure PostgreSQL](https://azure.microsoft.com/en-us/pricing/details/postgresql/) |\n\n*State of affairs as for June 2025*\n\n---\n\n## ☁️ Awesome Free (or Generous Trial) Shell Hosting for Remote Docker Swarm \u0026 n8n Frontend\n\n| 🏢 Service | 💸 Free Tier / Trial Highlights | 🔗 Link |\n|-----------|---------------------------------|---------|\n| 🚀 **[Google Cloud Shell](https://cloud.google.com/shell)** – Fully featured shell environment with 5 GB persistent storage | 🆓 Always free, built-in Docker support, easy to connect via browser, perfect for lightweight dev \u0026 Docker experiments | 🌐 [Google Cloud Shell](https://cloud.google.com/shell) |\n| 🐳 **[Railway](https://railway.app/)** – Developer-friendly cloud with free tier for containers and shell access | 🆓 $5 monthly credit (~500 hours), easy deployment, Docker support, persistent volumes | 🎉 [Railway Free Tier](https://railway.app/pricing) |\n| ☁️ **[Fly.io](https://fly.io/)** – Global app hosting with Docker container support, 3 shared CPUs | 🆓 3 shared CPUs, 256 MB RAM, 3 GB persistent volume, free 1600 CPU hours/month | ✈️ [Fly.io Free Tier](https://fly.io/docs/about/pricing/) |\n| 🐧 **[Oracle Cloud Free Tier](https://www.oracle.com/cloud/free/)** –  Always free compute instances with shell access | 🆓 2 AMD VMs with 1/8 OCPU each, 1 GB RAM, Docker installable, 100 GB block storage | 🐘 [Oracle Cloud Free Tier](https://www.oracle.com/cloud/free/) |\n| 🦄 **[AWS Free Tier (EC2)](https://aws.amazon.com/free/)** – Free micro instance for 12 months with full shell access | 🆓 750 hrs/month t2.micro/t3.micro, Docker installable, perfect for small dev projects | ☁️ [AWS Free Tier](https://aws.amazon.com/free/) |\n| 🐳 **[DigitalOcean App Platform](https://www.digitalocean.com/products/app-platform/)** – Easy Docker container deploy with free starter plan | 🆓 Starter tier with 3 static sites, 1 container, 100 GB bandwidth | 🚀 [DigitalOcean App Platform](https://www.digitalocean.com/pricing/) |\n\n*State of affairs as for June 2025*\n\n---\n\n## 🐵 Development plans:\n\n- Kubernetes orchestration of containers with various customizable settings.\n- Increase of installation options of popular services n8n connects to on setup.\n- A script to dump workflows and creds from n8n regularly (via API or CLI). Re-import them with new keys and never lose your data.\n- Much more to come...\n\n---\n\n© 2025 Paweł Kochanowicz · [GitHub](https://github.com/pkochanowicz)\n\nThis project is licensed under the [MIT License](LICENSE).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkochanowicz%2Fn8n-setup-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkochanowicz%2Fn8n-setup-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkochanowicz%2Fn8n-setup-docker/lists"}