How can I specify run arguments for a Dockerimage deploy?

I’ve deployed a QuestDB image but I’m only able to access port 9000 when I also need port 9009, I would also like to link a fly.io volume and I guess that would be done by creating a fly volume and using the -v argument on the docker run command to link them, this is the docker command that should be run with the image:

docker run \
  -p 9000:9000 -p 9009:9009 -p 8812:8812 -p 9003:9003 \
  -v "$(pwd):/var/lib/questdb" \
  questdb/questdb

Is there a way to set the -p and -v run arguments when deploying? This is how my Dockerfile and fly.toml look like:

Dockerfile

FROM questdb/questdb:latest
EXPOSE 9000 9009

fly.toml

# fly.toml file generated for bbitqdbdev on 2023-03-10T21:09:48-06:00

app = "bbitqdbdev"
kill_signal = "SIGINT"
kill_timeout = 5
primary_region = "qro"
processes = []

[env]

[experimental]
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 9000
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

[[services]]
  http_checks = []
  internal_port = 9009
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 9009

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

I’m really new to fly.io so any help or pointers would be appreciated. Thank you! :slight_smile:

2 Likes

Welcome!

I think one thing that make your life very simple is using our Machines flyctl command.

Here’s an example of how I used it to run a Code Server (explanations on that link):

fly machine run . \
  -p 443:8080/tcp:tls \
  -p 4000:4000/tcp:tls \
  --memory 1024 \
  --region <your-region> \
  --volume storage:/project \
  --env FLY_REMOTE_BUILDER_HOST_WG=1 \
  --env GIT_REPO=https://github.com/fly-apps/hello_elixir_sqlite.git \
  -a <your-app-name>

Hope this helps and we :heart: machines so much soon :tm: all apps will use machines (without you having to learn anything).

What if I want to run a docker image hosted on Docker Hub?

Locally I run the image like this:

docker run cloudflare/cloudflared:latest tunnel --no-autoupdate run --token XXXX 

You can change the . after fly machine run to something/something:tag

$ fly m run --help
Run a machine

Usage:
  flyctl machine run <image> [command] [flags]

Flags:
  -a, --app string           Application name
      --build-nixpacks       Build your image with nixpacks
  -c, --config string        Path to application configuration file
      --cpus int             Number of CPUs
      --detach               Return immediately instead of monitoring deployment progress
      --dockerfile string    Path to a Dockerfile. Defaults to the Dockerfile in the working directory.
      --entrypoint string    ENTRYPOINT replacement
  -e, --env strings          Set of environment variables in the form of NAME=VALUE pairs. Can be specified multiple times.
  -h, --help                 help for run
      --id string            Machine ID, if previously known
      --kernel-arg strings   List of kernel arguments to be provided to the init. Can be specified multiple times.
      --memory int           Memory (in megabytes) to attribute to the machine
  -m, --metadata strings     Metadata in the form of NAME=VALUE pairs. Can be specified multiple times.
  -n, --name string          Machine name, will be generated if missing
      --org string           The organization that will own the app
  -p, --port strings         Exposed port mappings (format: (edgePort|startPort-endPort)[:machinePort]/[protocol[:handler]])
  -r, --region string        The target region (see 'flyctl platform regions')
      --schedule string      Schedule a machine run at hourly, daily and monthly intervals
  -s, --size string          Preset guest cpu and memory for a machine, defaults to shared-cpu-1x
  -v, --volume strings       Volumes to mount in the form of <volume_id_or_name>:/path/inside/machine[:<options>]

Global Flags:
  -t, --access-token string   Fly API Access Token
  -j, --json                  json output
      --verbose               verbose output
1 Like

@lubien

When I try to run

fly m run cloudflare/cloudflared:latest tunnel --no-autoupdate run --token xxxx

I got the error:

Error unknown flag: --no-autoupdate

If I remove it, I got, Error unknown flag: --token

But I need those both flags.

UPDATE:

Got it. I had to run:

fly m run cloudflare/cloudflared:latest --entrypoint "cloudflared tunnel --no-autoupdate run --token ABCDXXXXXXXXTOKEN" -a APP_NAME
1 Like

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