I’m running n8n on my own server as part of our system. We need to set up the admin account in a specific way so we can get an API key for our deployment process, tests, and live environment. Here’s what our docker-compose setup looks like:
We’re using a custom database, so maybe we could add the user with SQL? The n8n docs talk about setting up the owner, but don’t say how to do it automatically. Any ideas on how to make this happen without manual steps?
As someone who’s set up n8n in various environments, I can share a trick that’s worked well for me. Instead of messing with the database directly, you can use n8n’s CLI to create the admin user programmatically. Here’s what I do:
Add a custom entrypoint script to your n8n service in the docker-compose file.
In this script, use the n8n CLI to create the user if it doesn’t exist.
I’ve encountered a similar challenge in my n8n deployments. One effective approach is to leverage environment variables in your docker-compose file. You can set variables for the admin email, password, and other details, then use n8n’s built-in environment variable support to configure the initial user.
Add something like this to your n8n service environment:
n8n will automatically create this user on first run if it doesn’t exist. This method avoids direct database manipulation and works seamlessly with n8n’s internal user management system. Remember to use strong, unique passwords and consider using Docker secrets for sensitive information in production environments.