Dockerizing a Remotion app
We recommend the following structure for your Dockerfile. Read below about the individual steps and whether you need to adjust them.
Dockerfiledocker
FROM alpine:3.17# Install necessary packagesRUN apk updateRUN apk add --no-cache chromium-swiftshader="109.0.5414.74-r0" ffmpeg="5.1.2-r1" nodejs-current="19.3.0-r0"# Add a user so Chrome can use the sandbox.RUN addgroup -S remotion && adduser -S -g remotion remotionRUN mkdir -p /out /node_modulesRUN chown -R remotion:remotion /node_modules /out# Copy everything from your project to the docker image. Adjust if needed.COPY package.json package*.json yarn.lock* pnpm-lock.yaml* tsconfig.json* remotion.config.* ./COPY src ./srcCOPY public ./public# Install the right package manager and dependencies - see below for Yarn/PNPMRUN npm i# Run everything after as non-privileged user.USER remotion# Run your applicationCOPY render.mjs render.mjsCMD ["node", "render.mjs"]
Dockerfiledocker
FROM alpine:3.17# Install necessary packagesRUN apk updateRUN apk add --no-cache chromium-swiftshader="109.0.5414.74-r0" ffmpeg="5.1.2-r1" nodejs-current="19.3.0-r0"# Add a user so Chrome can use the sandbox.RUN addgroup -S remotion && adduser -S -g remotion remotionRUN mkdir -p /out /node_modulesRUN chown -R remotion:remotion /node_modules /out# Copy everything from your project to the docker image. Adjust if needed.COPY package.json package*.json yarn.lock* pnpm-lock.yaml* tsconfig.json* remotion.config.* ./COPY src ./srcCOPY public ./public# Install the right package manager and dependencies - see below for Yarn/PNPMRUN npm i# Run everything after as non-privileged user.USER remotion# Run your applicationCOPY render.mjs render.mjsCMD ["node", "render.mjs"]
Line-by-line
docker
FROM alpine:3.17RUN apk update
docker
FROM alpine:3.17RUN apk update
chromium-swiftshader
: The headless version of Chrome.swiftshader
is required for WebGL, if you don't require it, you can replacechromium-switftshader
withchromium
.ffmpeg
: Required for video encoding.nodejs-current
: Node.js to run Remotion.npm
: The package manager. If you intend to useyarn
orpnpm
, you can remove this line.
docker
RUN apk updateRUN apk add --no-cache \chromium-swiftshader="109.0.5414.74-r0" \ffmpeg="5.1.2-r1" \nodejs-current="19.3.0-r0" \npm="9.1.2-r0"
docker
RUN apk updateRUN apk add --no-cache \chromium-swiftshader="109.0.5414.74-r0" \ffmpeg="5.1.2-r1" \nodejs-current="19.3.0-r0" \npm="9.1.2-r0"
remotion
.
docker
RUN addgroup -S remotion && adduser -S -g remotion remotionRUN mkdir -p /out /node_modulesRUN chown -R remotion:remotion /node_modules /out
docker
RUN addgroup -S remotion && adduser -S -g remotion remotionRUN mkdir -p /out /node_modulesRUN chown -R remotion:remotion /node_modules /out
The COPY
syntax allows multiple files, but at least one file must exist. It is assumed package.json
, src
and public
exist in your project, but you can adjust this to your needs.
docker
COPY package.json package*.json yarn.lock* pnpm-lock.yaml* tsconfig.json* remotion.config.* ./COPY src ./srcCOPY public ./public
docker
COPY package.json package*.json yarn.lock* pnpm-lock.yaml* tsconfig.json* remotion.config.* ./COPY src ./srcCOPY public ./public
If you use NPM, put the following in your Dockerfile:
dockerRUN npm idockerRUN npm iIf you use Yarn or PNPM, add the
packageManager
field to yourpackage.json
(example:"packageManager": "pnpm@7.7.1"
) and remove thenpm
line from step 2. Then put following in your Dockerfile:If you use PNPMdockerRUN corepack enableRUN pnpm iIf you use PNPMdockerRUN corepack enableRUN pnpm iIf you use YarndockerRUN corepack enableRUN yarnIf you use YarndockerRUN corepack enableRUN yarn
remotion
user.
docker
USER remotion
docker
USER remotion
docker
COPY render.mjs render.mjsCMD ["node", "render.mjs"]
docker
COPY render.mjs render.mjsCMD ["node", "render.mjs"]
Example script:
render.mjsjs
import { bundle } from "@remotion/bundler";import { getCompositions, renderMedia } from "@remotion/renderer";import { createRequire } from "node:module";const require = createRequire(import.meta.url);const bundled = await bundle({entryPoint: require.resolve("./src/index.ts"),// If you have a Webpack override, make sure to import it herewebpackOverride: (config) => config,});const compositions = await getCompositions(bundled);const composition = compositions[0];console.log("Starting to render composition", composition.id);await renderMedia({codec: "h264",composition,serveUrl: bundled,outputLocation: `out/${composition.id}.mp4`,});console.log(`Rendering composition ${composition.id}...`);
render.mjsjs
import { bundle } from "@remotion/bundler";import { getCompositions, renderMedia } from "@remotion/renderer";import { createRequire } from "node:module";const require = createRequire(import.meta.url);const bundled = await bundle({entryPoint: require.resolve("./src/index.ts"),// If you have a Webpack override, make sure to import it herewebpackOverride: (config) => config,});const compositions = await getCompositions(bundled);const composition = compositions[0];console.log("Starting to render composition", composition.id);await renderMedia({codec: "h264",composition,serveUrl: bundled,outputLocation: `out/${composition.id}.mp4`,});console.log(`Rendering composition ${composition.id}...`);
Building a docker image
Run
sh
docker build -t remotion-app .
sh
docker build -t remotion-app .
to build a docker image called remotion-app
. Use the following command to run the image:
sh
docker run remotion-app
sh
docker run remotion-app