December 10, 2023

Install Chromium in an Ubuntu Docker container

Install Chromium in an Ubuntu Docker container

Running Chrome or Chromium in a container is incredibly useful to run tests, build web scrapers, or to make screenshots of web pages - but unfortunately installing Chromium is no longer supported using `apt` on Ubuntu:

```
$ apt update && apt install -y chromium-browser
$ chromium-browser
Command '/usr/bin/chromium-browser' requires the chromium snap to be installed.
Please install it with:
snap install chromium
```

This is problematic because snap does not work from within a Docker container. There are some other options:

  1. There's a PPA with Chromium builds but this only publishes x86 binaries. So this won't work on Macbook's or arm64 servers. In addition this requires you to trust binaries from a random person.
  2. Google does provide .deb files for Chrome, but again, they only publish x86 binaries here. So this won't work either for many developers.
  3. The Debian package registry does contain Chromium builds for x86 and arm64, and adding the Debian registry as a package source does let you install Chromium on Ubuntu (instructions here). The downside of this is that you're relying on an unofficial package registry - and thus this approach might break at any moment.

Another big issue with these approaches is that there's no versioning. You'll always get the latest version of Chrome / Chromium. Fine if you're just visiting websites on your laptop, but if you use this in your test infra or in production then this might break your tests or application any time the container gets rebuilt.

To fix this we've built StableBuild. We mirror the complete Ubuntu and Debian package registries (plus a lot more!) every day, and thus let you easily install _specific_ Chromium versions on Ubuntu (by pinning to a specific date of the Debian package registry). Here's how it works:

  1. Head to https://dashboard.stablebuild.com and sign up (there's a free Community plan available).
  2. Go to Dashboard > Deb repository.
  3. Select the date that you want to pin - the Chromium version published on that day will be installed.
  4. Select the 'Chromium' package repository.
  5. Update your Dockerfile with the instructions.

And done!

Installing instructions for Chromium on Ubuntu with StableBuild

You now have a working version of Chromium in your container (here ran on Ubuntu 22.04 with pin date 2023-12-09T10:40:02Z):

```
$ chromium --version
Chromium 116.0.5845.180 built on Debian 12.1, running on Debian bookworm/sid
```

In addition Chromium is now pinned. This container will now always install Chromium 116, and thus your containers won't randomly break due to an unsupported or untested update.

If you also need Chromedriver, e.g. to run tests, then run:

```
$ apt install -y chromium-driver
```

🎉

Note: A downside is that you're constrained to Chromium versions that are published in the Debian package registry (as that's what we mirror), which typically is behind the latest stable version. E.g. on the 2023-12-09 pin date above the Debian registry contains Chromium 116, while Chromium 120 has already been released on other channels.