is a convenient and easy to use deployment platform with a generous free allowance. They’re also a sponsor of the Gleam project, thank you Fly!

Prepare an application

We will need a Gleam backend web application to deploy in this guide, so first we will make one. If you already have an application skip to the next section.

Create a new Gleam project and add the required dependencies.

gleam new my_web_app
cd my_web_app
gleam add mist gleam_http gleam_erlang

Open up src/my_web_app.gleam and replace the contents with this code that defines a micro web application.

import mist
import gleam/erlang/process
import gleam/bit_builder
import gleam/http/response.{Response}

pub fn main() {
  assert Ok(_) = mist.run_service(8080, web_service, max_body_limit: 4_000_000)

fn web_service(_request) {
  let body = bit_builder.from_string("Hello, Joe!")
  Response(200, [], body)

Now we have a web application that listens on port 8080 and can be started with gleam run.

Add a Dockerfile

We can use Fly’s support for containers to build the application and prepare it for deployment.

Add a file named Dockerfile with these contents:


# Add project code
COPY . /build/

# Compile the project
RUN cd /build \
  && gleam export erlang-shipment \
  && mv build/erlang-shipment /app \
  && rm -r /build

# Run the server
ENTRYPOINT ["/app/"]
CMD ["run"]

Set up the CLI

Follow the instructions here to install Flyctl, the command-line interface for the platform.

Once installed use the CLI to sign up (or log in if you already have a account).

fly auth signup
# OR
fly auth login

Fly’s free allowance is enough to run the Gleam application but new accounts need a payment card to be added, to prevent people from abusing Fly’s free service.

Deploy the application

From within the project use the Fly CLI to create and run your application on their platform.

flyctl launch

The CLI will ask you a series of questions:

Once you have answered these it will build the application using the docker file. Once deployed you can open it in a web browser by running flyctl open.

To deploy future versions of the application run flyctl deploy after saving any changes to the source code.