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.
DockerfiledockerFROM 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"]
DockerfiledockerFROM 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
dockerFROM alpine:3.17RUN apk update
dockerFROM alpine:3.17RUN apk update
chromium-swiftshader: The headless version of Chrome.swiftshaderis required for WebGL, if you don't require it, you can replacechromium-switftshaderwithchromium.ffmpeg: Required for video encoding.nodejs-current: Node.js to run Remotion.npm: The package manager. If you intend to useyarnorpnpm, you can remove this line.
dockerRUN 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"
dockerRUN 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.
dockerRUN addgroup -S remotion && adduser -S -g remotion remotionRUN mkdir -p /out /node_modulesRUN chown -R remotion:remotion /node_modules /out
dockerRUN 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.
dockerCOPY package.json package*.json yarn.lock* pnpm-lock.yaml* tsconfig.json* remotion.config.* ./COPY src ./srcCOPY public ./public
dockerCOPY 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
packageManagerfield to yourpackage.json(example:"packageManager": "pnpm@7.7.1") and remove thenpmline 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.
dockerUSER remotion
dockerUSER remotion
dockerCOPY render.mjs render.mjsCMD ["node", "render.mjs"]
dockerCOPY render.mjs render.mjsCMD ["node", "render.mjs"]
Example script:
render.mjsjsimport { 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.mjsjsimport { 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
shdocker build -t remotion-app .
shdocker build -t remotion-app .
to build a docker image called remotion-app. Use the following command to run the image:
shdocker run remotion-app
shdocker run remotion-app