Skip to main content

deploying images to fly.io

·3 mins

Fly.io is a Platform as a Service (PaaS) enabling developers to deploy and run their applications globally, closer to their users. The Fly.io platform, notable for its simplicity and user-friendly design, has recently gained popularity.

Fly.io transforms Docker containers into Firecracker VMs and strategically deploys them worldwide. There are a couple of different ways to build and deploy applications on Fly.io, the most straightforward method involves the flyctl CLI tool. With flyctl, you can effortlessly build and deploy your application using the single command flyctl deploy. However, this article will explore other deployment strategies.

With Continuous Integration (CI) and Continuous Deployment (CD) workflows, you’ll build and push your Docker images to a container registry. This practice facilitates a consistent build process for images and deploying the same image across various environments. This article will show you how to push Docker images to Fly.io’s container registry for deployment.

Tagging Images #

When building and pushing Docker images to external registries, it’s essential to tag the image with the registry’s URL. For Fly.io, the container registry URL is registry.fly.io. Like with other registries, you must include both an image name and a tag. For instance, when using Docker Hub, you tag an image as follows:

registry.hub.docker.com/library/<dockerimagename>:<tag>

For Fly.io, the tagging format is:

registry.fly.io/<your-app>:<tag>

The key distinction is that, unlike Docker Hub, where your Docker image name can be arbitrary, with Fly.io, it must match your application’s name.

You can tag your Docker image using the following Docker command:

❯ docker tag myapp:latest registry.fly.io/myapp:latest

You can also tag your Docker image on build using the docker build command:

❯ docker build -t registry.fly.io/myapp:latest .

Pushing Images #

Pushing Docker images to external registries, like Docker Hub or Fly.io, involves tagging your image with the registry’s URL, image name, and tag. External registries allow for secure storage and easy distribution of your containerised applications. Before pushing Docker images, you must authenticate with the external registry.

To authenticate with Fly’s container registry, you can use the flyctl CLI tool. The command is as follows:

❯ flyctl auth docker
Authentication successful. You can now tag and push images to registry.fly.io/{your-app}

This command authenticates your Docker client with Fly.io’s container registry, allowing you to push images to the registry. This process works by creating an entry in your ~/.docker/config.json file, and for macOS users, it also adds the username and password to your keychain.

Now that you’re authenticated, push it to Fly.io’s container registry.

❯ docker push registry.fly.io/myapp:latest

Deploying An Image #

Once a Docker image is pushed to Fly.io’s container registry, you can deploy it to one of your Fly applications. The flyctl CLI tool provides a simple command to deploy your application using the Docker image from the registry.

❯ flyctl deploy --app myapp \
  --image registry.fly.io/myapp:latest

In future articles and projects, I plan to delve deeper into using manually tagged docker images within CI/CD pipelines. One use case involves pushing and deploying images to ensure consistent builds across multiple environments.