Deploying to Fly with Docker
With our Docker file ready, we can now deploy our app using Fly.
Fly makes deploying Docker simple. To get started, run
It will ask for an app name, which must be globally unique across Fly. You can enter a descriptive name or leave it blank for an autogenerated on
Man: 0:00 With our Dockerfile in place, Fly knows how to deploy Docker really well. All we have to do is run Fly launch. It's going to ask us a couple of questions. It sees that we've got a Dockerfile. That's great. It's going to ask us our app name. This needs to be globally unique across all of Fly.
0:15 Feel free to guess something that you think might be unique, if it's more descriptive for you, or you can leave it blank. It'll generate one that's not at all descriptive, but sometimes kind of fun. We'll go ahead and let it generate one for us.
0:27 Then it's going to ask us what region we want our thing to be running in. It automatically highlights the one that's closest to you. Of course, we want to deploy to multiple regions, but we've got to deploy to one region first. We'll go ahead and deploy to the one that's closest to me, which is San Jose. Then it creates the app.
0:47 If we go to this admin URL, we're going to see the app there. We'll look at that in a moment. It also tells us where our app is going to be hosted. It's basically just your appname.fly.dev. Then it wrote a config file for us. Let's take a look at that config file. Here it is. There's our app name.
1:03 We've got some pretty standard Fly config stuff in here. I'm not going to belabor all of this. If you want to learn more about the Fly config, then you can go to fly.toml. Just Google fly.toml. You'll find the documentation page. I promise this is such a wonderful read.
1:20 You should grab a hot chocolate and a pillow and snuggle up as you read through all of this wonderful documentation about a toml file. Have fun. [laughs] With that now, it's asking us more questions. Do we want to set up Postgres? Not really. Do we want to set up Redis? Not for this.
1:37 Both of those services are managed and deployed to the edge with read replicas and stuff. It's actually very cool. If that's something you want to do, definitely give it a shot. Now it's asking us if we want to deploy. Let's go ahead and deploy.
1:49 It's going to build our image on a remote builder. What Fly is doing now, is it actually creates a special app in our account that is completely free, that is going to be responsible for building our Docker images remotely.
2:03 We don't have to build them locally. We can do this really easily on GitHub Actions or whatever we want to do. That's quite nice, that it will build remotely. If we go to our dashboard now, we're going to see the new app we created as well as that builder app.
2:17 It's quite the beast of a machine with 50 gigabytes of storage. [laughs] It works perfectly. Again, it is completely free. Coming back to this, we're seeing that we're uploading our image to Fly. Then, once Fly gets that image, it's going to deploy it for us. While we're waiting for that, I want to show you a couple of things.
2:37 Now that we have an app, we can say "Fly logs." It will read our fly.toml to know which app we want logs for. It will start printing out logs as soon as our app starts getting logs. Now with another terminal, we'll say "Fly status." This will give us the status of our app currently. Since it's not deployed, we don't have any instances of it.
2:57 If we want to keep up with what's going on, we can say "Fly status --watch." Now this will keep us up to date with what is happening. Right now, our status is "Deployment is running." This will stay up to date as the deployment proceeds.
3:12 Then the last thing I want to show you is Fly open. That's going to open up to our application, which by golly, it's [laughs] already deployed. We can increment, we can decrement. Everything is working perfectly.
3:25 If we look at the logs now, we can see that they were starting up the instance. They pulled the virtual machine we deployed, and then applied migrations, and then started up the app. As soon as our app started being able to respond to basic TCP checks, then Fly was like, "OK. This must be ready to go." It deployed.
3:48 On HTTPS, we didn't have to worry about any of that. All we did was create a Dockerfile and then said, "Fly launch." Then Fly took care of the rest. That is, to me, a really awesome experience to not have to worry about managing servers or anything like that. That's us in production on Fly.