How can I use docker run arguments in my deploy?

I want to be able to run docker run commands to create instances of applications on demand

i.e.

docker run -d --name='test' -p 3303:3303 --env USERNAME=admin dockerhub/image:latest

However, I understand that Fly.io only allows you to publish already-existing images via flyctl deploy and thus the docker run doesn’t exist in this context

How can I replicate the behaviour of docker run (the ability to configure arguments) when deploying an existing image via flyctl?

In my example, I don’t really care about the docker instance name, but I do care about the port mapping and --env variables

flyctl deploy -i registry.fly.io/$PROJECT:latest can be used to point to an image.
flyctl deploy -e KEY=VAL can be used to set more than one env variables.

Do note that env variables supplied here will not be available during the build.

Not sure about the port though…
EDIT: Something like this for ports maybe; in your fly.toml:

  [[services.ports]]
    port = ${PUHRT}

and then flyctl deploy -e PUHRT=9000

https://fly.io/docs/reference/configuration/#the-env-variables-section says that env variables can only be strings. I reckon it’s easy enough to test & find out.

https://fly.io/docs/flyctl/deploy/

1 Like