Guides for common flyctl patterns

SSH into a Fly Instance

For a lot of people, the idea of a container is that it’s sort of hermetically sealed; you aren’t mean to peek inside and muck with a running instance, and if you want to make a change, you replace the running container with another newly built container.

But not all apps are built that way, and even for cattle-fleet apps running on ephemeral containers, sometimes the fastest way to debug a problem is to pop a shell.

You can easily SSH into any of your instances with flyctl. Here’s how.

Make Sure You’ve Got A Recent flyctl

Now’s a good time to run flyctl version update. What you want is a flyctl that has the flyctl ssh console command.

Make Sure You’re Logged In

I know, we’re asking if it’s plugged in. But: is it plugged in? Try flyctl apps list. If you can see your app, you should be able to log in.

(Optionally) Be In Your App Directory

You can deploy a bunch of different apps to Fly from the same host, so we need to know which one you want to talk to. flyctl will read the fly.toml file for your app from the current directory, so that’s one way to pick an app to log into.

Log In With SSH

This is going to be anticlimactic:

Run flyctl ssh console -s. You’ll see a prompt like this:

> $ flyctl ssh console -s                                                                                                       
Looking up regions in DNS... complete!
? Select instance:  [Use arrows to move, type to filter]
> lhr (fdaa:0:18:a7b:a98:1e25:4045:2)
  lhr (fdaa:0:18:a7b:a98:b208:7c5c:2)
  ord (fdaa:0:18:a7b:60:bc71:6132:2)
  gru (fdaa:0:18:a7b:60:9b4:1fdb:2)

Pick the instance you want to log in to, and then:

Looking up regions in DNS... complete!
? Select instance: lhr (fdaa:0:18:a7b:a98:8697:8018:2)
Connecting to [fdaa:0:18:a7b:a98:1e25:4045:2]... complete
# hostname
1e254045
# 

You’ve got a shell. Use it in good health.

If you don’t want to bother selecting a specific node, you can run flyctl ssh console (without the -s) and we’ll pick one for you.

On the other hand: if you know exactly what region you want to log in to, you can run (say) flyctl ssh console lhr.myapp.internal (all your apps have “app-name.internal” DNS names).

A bunch of stuff is happening under the hood here, and you can read more about it if you want. But you don’t have to, if all you need is a shell so you can get your work done.

1 Like