Phoenix Elixir app, how to iex into it using app-name(s) given by fly.io ?

fly ssh console --pty -C "/app/bin/<my_app_name> remote"

is from IEx into Your Running App · Fly Docs

But the <my_app_name> here is NOT the fly.io-name listed by cmd flyctl apps list (fly apps list · Fly Docs).

In my situation, I deploy 2 different branches onto fly.io, 1 web app is STAGING, the other is PROD.

Is there a way for me to use the “app name” chosen when creating the fly.io app (on fly.io dashboard) when trying to iex into my STAGING / PROD ?

The app name will be whatever you’ve named your app in mix.exs. Check in the project function for the app key.

You can confirm by SSHing into the server and looking in the bin directory.

For example, I have an app called oban_example and here’s what those commands do for me:

$ fly ssh console -a oban-example

Connecting to fdaa:3:6e52:a7b:105:a3f0:dae4:2... complete

root@3d8d9793a26738:/app# ls -alh bin
total 40K
drwxr-xr-x 2 nobody root 4.0K Nov 16 00:22 .
drwxr-xr-x 6 nobody root 4.0K Nov 16 00:22 ..
-rwxr-xr-x 1 nobody root   93 Nov 16 00:22 migrate
-rwxr-xr-x 1 nobody root   59 Nov 16 00:22 migrate.bat
-rwxr-xr-x 1 nobody root 5.3K Nov 16 00:22 oban_example
-rwxr-xr-x 1 nobody root 6.5K Nov 16 00:22 oban_example.bat
-rwxr-xr-x 1 nobody root   82 Nov 16 00:22 server
-rwxr-xr-x 1 nobody root   52 Nov 16 00:22 server.bat

Hope this helps!

1 Like

I understand it this way too.
For my project named “dummy”, I’d like to deploy 1 branch to STAGING, then another branch to PROD. Both are 1 and the same repo, therefore, 1 and the same “app name”, “dummy”.
So when I iex into “dummy”, which one am I going into? By observation, it seems I’m going into the latest deployed one. But how would go iex into the other app?
Has fly.io not considered companies with a project that want to deploy more than 1 branch, from the same repo?
Or, do you suggest that, as I switch branches, change my mix.exs so that I’m essentially deploying a different app name?

We definitely support deploying staging and production apps, however, we’re not super opinionated about how you separate them.

fly deploy will build and deploy whatever branch to the app that’s named in fly.toml. If you deploy the prod branch, switch to staging and deploy that branch, you’ll be building a new release from that branch and deploying to the same app.

The most simple way to create different environments is to create a new app. You can do this by running fly apps create app-name-you-want and then copying your fly.toml to fly.staging.toml and renaming the app key to whatever you used as the app name when you ran fly apps create.

Once this is done, deploy it with fly deploy -c fly.staging.toml

(Sorry for the edits, accidentally hit “post” too soon!)

Thanks for the helpful tip.
My project is called “dummy” as per mix.exs. I have successfully deployed to both fly apps (called “dummy-staging” and “dummy-prod”) under my fly account. Could you specifically explain how I can iex into each?
The complication is that the official command to iex must be fly ssh console --pty -C "/app/bin/dummy remote", in which I must use the name “dummy” from mix.exs. I wish I could specify either of the fly app names (dummy-staging or dummy-prod). As of right now, I can only iex into 1 of the running apps (specifically the most recently deployed one), and have no way to iex into the other.

There’s a flag for specifying the app. By default it picks the app in fly.toml.

I think fly help ssh console should list the options. I’m on my phone right now so I can’t check.

1 Like

We have 2 different commands in dicussion:
Command A. SSH into machine by fly ssh console -a <app_name_from_fly>
Command B. iex into the running-app console by fly ssh console --pty -C "/app/bin/<app_name_from_mix_dot_exs_NOT_app_name_from_fly> remote"

Luckily, I can now combine Command A with another command from Connect to running app with iex? - #2 by RudManusachi - Questions / Help - Elixir Programming Language Forum , in order to first SSH into machine where the app is running, then link to the iex console of the running app. This takes 1 extra step, but works reliably.

Nonetheless, it seems I’ve discovered a shortcoming of Command A. i.e. In the situation where the same mix.exs app-name is deployed into multiple fly-app names, Command A allows me to iex into ONLY the most recently deployed fly-app, which sometimes is “STAGING”, and sometimes is “PROD”.
Would you be able to improve Command B, to allow the ability to specify fly-app names, instead of mix.exs app-names?

Here’s the command. Focus on flag -a <name_of_fly_app>

fly ssh console --pty -C "/app/bin/<app_name_from_mix_dot_exs> remote" -a <name_of_fly_app>

Tip:

fly help ssh console

Many thanks to @matthewlehner 's helpful pointers.

Glad you go this figured out!

You can also SSH into the running machine and then run bin/app-name remote from there.

The -C flag just specifies the command that will be run when SSH connects. You can read more here: fly ssh console · Fly Docs

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