I’m running a self-hosted n8n instance using Docker and I need to automatically set up the administrator account during deployment. Our CI/CD pipeline requires an n8n API token for automated testing and production workflows, so manual setup through the web interface isn’t practical.
Here’s my current Docker setup with a PostgreSQL database:
Since I have direct access to the PostgreSQL database, I’m wondering if there’s a way to insert the admin user directly into the database tables or use environment variables to bypass the initial setup wizard. Has anyone found a solution for this?
you could also use docker secrets or init containers. just pipe the owner setup through a curl command that hits the api endpoint right after the container starts up. works great for automated deployments - no need to mess with the database directly.
You don’t need to mess with the database directly. I hit the same issue with our containerized setup and found n8n handles this automatically with environment variables. Just set N8N_OWNER_EMAIL, N8N_OWNER_PASSWORD, and N8N_OWNER_FIRST_NAME in your workflow-engine service config. On first startup with an empty database, n8n creates the admin account automatically - no manual steps needed. Watch out though - your database needs to be ready before n8n starts or the auto-creation fails silently. I’d add a health check or startup delay to make sure PostgreSQL is up. Once deployed, you can use those admin credentials to generate API tokens through the REST API for your CI/CD workflows.
I hit this same issue when deploying n8n in our Kubernetes cluster. Here’s what worked: add N8N_OWNER_EMAIL and N8N_OWNER_PASSWORD environment variables to your workflow-engine service config. When n8n starts up and sees these variables with an empty user table, it’ll auto-create the owner account - no web setup wizard needed. I’d also throw in N8N_SKIP_OWNER_SETUP=true to skip any interactive prompts entirely. Once the container’s up, use those owner credentials to authenticate with the API and generate tokens for your CI/CD pipeline. We’ve been running this setup in production for six months with zero issues.