Deploying with Docker
Relevant source files
The following files were used as context for generating this wiki page:
Rendertron is a headless Chrome rendering solution that can be deployed as a standalone HTTP server inside a Docker container. This allows for isolated, scalable, and portable deployments. While the project does not include a Dockerfile, it is designed to be containerized, and this guide outlines the official strategy and key considerations for doing so.
The core principle for deploying Rendertron with Docker is to follow the official documentation for its main dependency, Puppeteer. The Rendertron service is essentially a wrapper around Puppeteer, so a successful Puppeteer Docker deployment will result in a successful Rendertron deployment.
Sources: README.md:100-103
Core Deployment Strategy
The project explicitly delegates the Docker setup to the official Puppeteer documentation. This ensures that the deployment benefits from the latest best practices for running headless Chrome in a containerized environment, which is a non-trivial task that requires specific system dependencies.
Official Guidance:
Rendertron no longer includes a Docker file. Instead, refer to Puppeteer documentation on how to deploy run headless Chrome in Docker.
Sources: README.md:100-103
Key Considerations for Containerization
When creating a Dockerfile for Rendertron, several aspects of the application's structure and configuration must be taken into account.
Application Startup
The application is started via an npm script. The CMD or ENTRYPOINT of your Dockerfile should execute this command after building the project.
- Build command:
npm run build(compiles TypeScript to JavaScript) - Start command:
npm run start(executesnode build/rendertron.js)
Sources: package.json:13, package.json:15
Running Headless Chrome in Docker
A critical aspect of running Rendertron in Docker is ensuring the Puppeteer instance can launch Chrome correctly. The application code facilitates this by including the --no-sandbox argument when launching Puppeteer, which is essential for most Docker environments.
// src/rendertron.ts:28-28
const browser = await puppeteer.launch({args: ['--no-sandbox']});
This demonstrates that the application is already configured for a key requirement of containerized execution.
Sources: src/rendertron.ts:28-28
Configuration
Rendertron can be configured via a config.json file in the project root. When containerizing, this file should be copied into the image or mounted as a volume. The port specified in the configuration (or via the PORT environment variable) must be exposed in the Dockerfile.
| Property | Default | Description |
|---|---|---|
datastoreCache | false | Set to true to enable caching on Google Cloud using datastore. |
timeout | 10000 | The timeout in milliseconds for rendering a target page. |
port | 3000 | The port for the Rendertron service. Overridden by process.env.PORT. |
width | 1000 | The default viewport width for rendering. |
height | 1000 | The default viewport height for rendering. |
Sources: README.md:107-113, src/rendertron.ts:21-23
Conceptual Dockerization Flow
This diagram illustrates the high-level steps to build a Docker image for Rendertron. The "Install Chrome Dependencies" step is the most critical and should be implemented by following the official Puppeteer documentation.
This diagram shows a conceptual workflow for creating a Rendertron Docker image.
Sources: package.json, README.md:100-113
Architectural Overview
In a typical production setup, the Rendertron service runs in its own container. Another application (e.g., your main web server) uses a middleware to intelligently proxy requests from bots to the Rendertron container for server-side rendering.
This sequence diagram shows the interaction between a web application using rendertron-middleware and the Rendertron service running in a Docker container.
This diagram shows the request flow when a bot requests a page from an application using the Rendertron middleware to proxy to a Rendertron container.
Summary
To deploy Rendertron using Docker, you must build a custom Docker image based on the official Puppeteer guidelines. The Rendertron application is already equipped with necessary configurations, such as the --no-sandbox flag, to run smoothly in a container. The deployment involves creating a Dockerfile that installs Node.js, all necessary Chrome dependencies, the application's npm packages, and then runs the npm run start command. The containerized service is then used by a middleware in your primary application to serve pre-rendered content to bots.