Skip to content

how to deploy browserless image to fly

Posted on:November 22, 2023 at 12:00 AM

How to Deploy a Browserless Image to Fly.io

The browserless Docker image provides a Chromium instance that can be used for browser automation. Deploying this image to Fly.io allows it to be run in a scalable, serverless environment. Here are the steps to deploy browserless to Fly.io:

Build the Docker Image Locally

Create a simple Dockerfile that uses the browserless/chrome image:

FROM browserless/chrome:latest
ENV PORT "8080"

Build and test the image locally:

docker build -t localimaginary .
docker run -p 3001:8080 localimaginary

Deploy to Fly.io

First, install and authenticate the Fly CLI:

fly auth login

Initialize a new Fly app which generates a fly.toml file:

fly launch

The default memory allocation is 256MB which is too small for browserless. Scale it up to at least 512MB:

flyctl scale memory 512 -a "your-app-name" 

Use the Browserless Image

The browserless image can now be used from other apps by connecting to the WebSocket endpoint:

const puppeteer = require('puppeteer-core');

const browser = await puppeteer.connect({ 
  browserWSEndpoint: 'ws://your-fly-app-url' 
});

// Generate screenshots...

browser.close();

This allows the browserless service to be called on-demand without needing to run a dedicated server. Fly.io handles scaling and availability.