# How to correctly customize the n8n Dockerfile on Railway (without breaking login or DB migrations)?

**URL:** <https://community.n8n.io/t/how-to-correctly-customize-the-n8n-dockerfile-on-railway-without-breaking-login-or-db-migrations/100294>\
**Category:** Questions\
**Created:** [April 12, 2025, 11:39am UTC](https://community.n8n.io/t/how-to-correctly-customize-the-n8n-dockerfile-on-railway-without-breaking-login-or-db-migrations/100294 "2025-04-12T11:39:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AI\_Blueprint](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ai_blueprint/32/60222_2.png) [@AI\_Blueprint](https://community.n8n.io/u/AI_Blueprint)\
**Post date:** [April 12, 2025, 11:39am UTC](https://community.n8n.io/t/how-to-correctly-customize-the-n8n-dockerfile-on-railway-without-breaking-login-or-db-migrations/100294/1 "2025-04-12T11:39:44Z")

</div>

I’m running n8n on Railway (Primary + Worker + Postgres + Redis, using queue mode) and wanted to customize the Dockerfile to add tools like `curl` and `ffmpeg`.

After switching from the default `n8nio/n8n` image to a custom Dockerfile (as suggested in the docs), I ran into problems:

- Login fails with `column User.apiKey does not exist`
- Looks like migrations aren’t running
- Redis sometimes fails to connect in Worker mode

When I don’t use a Dockerfile (Railway default), everything works fine.

* * *

### **My Questions:**

1. Do both Primary and Worker need the Dockerfile separately?
2. Can I use one Dockerfile for both and control behavior via `N8N_ROLE`?
3. How do I make sure `n8n migrate:up` runs in Primary?
4. Why does login break after switching to Docker?

Would love a clear example or best practice for custom Docker on Railway. Thanks!

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [June 27, 2025, 8:30am UTC](https://community.n8n.io/t/how-to-correctly-customize-the-n8n-dockerfile-on-railway-without-breaking-login-or-db-migrations/100294/2 "2025-06-27T08:30:10Z")

</div>

Hey @AI_Blueprint,

Railway isn’t a platform we officially support but assuming you are using the same postgres and redis database it shouldn’t break unless the database is already in a bad state. Just changing a docker image unless you have done something really odd shouldn’t cause a problem.

How were you making the Dockerfile and was Railway previously using a Dockerfile or something else?

---

<div class="post-metadata">

**Author:** ![Wouter\_Nigrini](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/wouter_nigrini/32/150261_2.png) [@Wouter\_Nigrini](https://community.n8n.io/u/Wouter_Nigrini)\
**Post date:** [June 27, 2025, 8:52am UTC](https://community.n8n.io/t/how-to-correctly-customize-the-n8n-dockerfile-on-railway-without-breaking-login-or-db-migrations/100294/3 "2025-06-27T08:52:07Z")

</div>

Please can you share your custom Dockerfile in a code block. Redact any sensitive values.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [September 25, 2025, 8:52am UTC](https://community.n8n.io/t/how-to-correctly-customize-the-n8n-dockerfile-on-railway-without-breaking-login-or-db-migrations/100294/4 "2025-09-25T08:52:08Z")

</div>

Closed on September 25, 2025, 8:52am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
