[Fly.io] Use Fly.io to Deploy Your Application via Dockerfile
Deploy Your Application via Dockerfile
You already have a project wrapped up in a docker container - https://docs.docker.com/engine/reference/builder/ ? Great! Just deploy that!
The fly launch
command detects your Dockerfile and builds it. If you have Docker running locally, it builds it on your machine. If not, it builds it on a Fly build machine. Once your container is built, it’s deployed! Need some extra config? No sweat, we’ve got you covered. Let’s take a look.
1 | fly launch |
Let fly launch
generate an app name for you or pick your own.
Select the Fly.io region - https://fly.io/docs/reference/regions/ to deploy to. It defaults to the one closest to you.
The launch command generates a fly.toml
file for your project with the settings. You can deploy right away, or add some config first.
Config First!
Most Dockerfiles expect some configuration settings through ENV
. The generated fly.toml
file has a place for you to add your custom ENV
settings. It’s the [env]
block.
1 | # fly.toml |
Add whatever values your Dockerfile or container requires.
Sometimes you have secrets that shouldn’t be checked in to git or shared publicly. For those settings, you can set them using fly secrets.
1 | flyctl secrets set MY_SECRET=romance |
You can list the secrets you’ve already set using fly secrets list
1 | fly secrets list |
The values aren’t display since they are secret!
Deploy Your App
If you didn’t previously deploy the app, you can do that now.
1 | fly deploy |
If you have Docker running locally, it builds it on your machine. If you don’t have Docker running locally, it builds it on a Fly build machine. Once your container is built, it’s deployed!
See Your App
Run fly open
to open your deployed app in a browser.
1 | fly open |
You’re off and running!
Taking It Further
Lots of applications deployed in a container have some state that they want to keep. Here are a couple resources to check out for ways to do that.
-
Persistent Volumes - https://fly.io/docs/reference/volumes/: You can create persistent volumes that you can mount into your container for reading and writing data that changes but isn’t blown away when you deploy again.
-
Postgres Database: Deploy a Fly Postgres Database. It automatically creates a DATABASE_URL ENV` when you attach it to your app.
Refenrences
[1] Deploy Your Application via Dockerfile - https://fly.io/docs/getting-started/dockerfile/
[2] Deploy app servers close to your users · Fly - https://fly.io/
[3] Hands-on with Fly - https://fly.io/docs/hands-on/start/
[4] Deploy Your Application via Dockerfile - https://fly.io/docs/getting-started/dockerfile/
[5] Volumes - https://fly.io/docs/reference/volumes/
[6] Postgres on Fly - https://fly.io/docs/reference/postgres/#about-postgres-on-fly
[8] docker container - https://docs.docker.com/engine/reference/builder/