I’m running a self-hosted n8n workflow automation tool and need to automatically set up the admin user during deployment. Our team requires the API key for our CI/CD pipeline and production environment setup. Currently, we have to manually complete the owner configuration through the web interface, which is not ideal for automated deployments.
Here’s our current docker setup with MySQL database:
Is there a way to programmatically create the owner account through environment variables or database insertion? I’ve checked the official docs but they only show the manual setup process.
you can automate the admin setup by using the n8n API after the container starts. just send a POST request to /api/v1/owner/setup with the email and password in your script. works great for automating the whole thing!
Try using n8n CLI commands directly in your container setup. Create a custom entrypoint script that runs after n8n initializes but before it starts serving requests. Use n8n’s internal commands to create the admin user instead of hitting external APIs. I’ve had better luck mounting a startup script that uses n8n’s built-in user creation methods - way more reliable than API calls, especially when you’re dealing with timing issues between the database spinning up and the app being ready. Plus it avoids those annoying race conditions you get with API approaches during container orchestration.
Had the exact same problem when deploying n8n in production. Here’s what actually worked for me: create an init script that runs after the container starts. Set up a health check that waits for n8n to be ready, then hits /api/v1/owner/setup with your credentials. The trick is making sure the database is fully loaded before you try the setup call. I just used a bash script that polls the health endpoint first, then creates the owner. You can pass your admin credentials through environment variables and it’ll configure everything automatically during deployment - no manual setup needed.