Skip to content

Instantly share code, notes, and snippets.

@cprecioso
Last active October 10, 2025 14:00
Show Gist options
  • Select an option

  • Save cprecioso/e19e883138241c1a446f48d6187aae75 to your computer and use it in GitHub Desktop.

Select an option

Save cprecioso/e19e883138241c1a446f48d6187aae75 to your computer and use it in GitHub Desktop.
How to create custom PostgreSQL Docker images for Fly.io

How to create a custom PostgreSQL Docker image for Fly.io

Fly.io has some specific setup for PostgreSQL Docker images, which means that your best bet is to start from their base image and then customize it. Luckily, their base image is based on the official PostgreSQL repo for Ubuntu, so installing additional extensions is very easy.

  1. Choose a Dockerfile from below, we've provided two examples, one for pgvector and another for postgis.

    You can also create your own by following the same pattern, by adding the installation steps for the PostgreSQL extension you want to install.

  2. Login to Docker Hub:

    docker login
  3. Build and push the image to Docker Hub. Replace the variables below with your own values:

    username=your-dockerhub-username   # the user you just logged in to Docker Hub with
    image_name=custom-fly-docker       # or a more descriptive one, e.g. fly-postgis
    dockerfile=path-to-your-dockerfile # e.g. ./pgvector.Dockerfile or ./postgis.Dockerfile
    
    docker build --tag $username/$image_name --push --file $dockerfile .
  4. Ready! You can now use your new image when setting up your app with Wasp deploy. Replace the variables below with your own values:

    wasp deploy fly setup --db-image $username/$image_name $app_name $region
# syntax=docker/dockerfile:1
# check=skip=FromPlatformFlagConstDisallowed (Fly.io only has amd64 machines)
FROM --platform=linux/amd64 flyio/postgres-flex:17
RUN <<EOF
apt-get update -y
apt-get install -y postgresql-$PG_MAJOR_VERSION-pgvector
apt-get clean -y
EOF
# syntax=docker/dockerfile:1
# check=skip=FromPlatformFlagConstDisallowed (Fly.io only has amd64 machines)
FROM --platform=linux/amd64 flyio/postgres-flex:17
RUN <<EOF
apt-get update -y
apt-get install -y postgresql-$PG_MAJOR_VERSION-postgis-3
apt-get clean -y
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment