How to run a process as a specific user in an app?

In my fly.toml file, I have:

[processes]
  app = 'python -m main.py'

From my app’s deployment output, I can see:

2025-02-06T06:30:02Z app[48ed037a547458] bos [info] INFO Preparing to run: python -m main.py as root

How can I configure the process to run as user foo instead of root?

I discovered that adding the following to the Dockerfile works:

ARG USER_NAME=foo
USER ${USER_NAME}

This produces the desired output:

2025-02-06T06:30:02Z app[48ed037a547458] bos [info] INFO Preparing to run: python -m main.py as foo

However, I’m wondering if we can achieve the same result without modifying the Dockerfile, perhaps using fly.toml or another approach? I was surprised to find that this configuration option isn’t documented in App configuration (fly.toml) · Fly Docs

I’m not sure if that’s the fly.toml’s responsibility. Defining the user in the Dockerfile is pretty standard. It’s literally 1 line.

I was thinking it would be nice to use user: foo in docker-compose.yml for local development and have something similar in fly.toml for production, while keeping the Dockerfile untouched

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