Firefox Installation In Ubuntu 24.04 Docker Images

Introduction

We used to install Firefox via apt-get install firefox in Ubuntu Docker images. However, starting from Ubuntu 22.04, the Firefox installed via this approach cannot be launched in the Docker container.

1
2
3
4
5
$ firefox
Command '/usr/bin/firefox' requires the firefox snap to be installed.
Please install it with:

snap install firefox

It seems that we would have to install Firefox via snap instead of apt-get in Ubuntu 22.04 and later. However, it is not quite possible to install snap in Docker images due to the lack of systemd in the Docker container.

In this blog post, I would like to quickly show how to install Firefox in Ubuntu 24.04 Docker images.

Firefox Installation In Ubuntu 24.04 Docker

The Dockerfile for Firefox installation in Ubuntu 22.04 or 24.04 can be configured as follows.

firefox.Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

# Install package dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
software-properties-common \
autoconf \
automake \
libtool \
pkg-config \
ca-certificates \
locales \
locales-all \
wget && \
apt-get clean

# System locale
# Important for UTF-8
ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US.UTF-8

# Install Firefox and its dependencies
# https://support.mozilla.org/en-US/kb/install-firefox-linux
# https://www.mozilla.org/en-US/firefox/117.0/system-requirements/
RUN install -d -m 0755 /etc/apt/keyrings && \
wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null && \
gpg -n -q --import --import-options import-show /etc/apt/keyrings/packages.mozilla.org.asc | awk '/pub/{getline; gsub(/^ +| +$/,""); if($0 == "35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3") print "\nThe key fingerprint matches ("$0").\n"; else print "\nVerification failed: the fingerprint ("$0") does not match the expected one.\n"}' && \
echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null && \
echo 'Package: *\nPin: origin packages.mozilla.org\nPin-Priority: 1000' | tee /etc/apt/preferences.d/mozilla && \
apt-get update && apt-get install -y --no-install-recommends \
libpci-dev \
libcanberra-gtk3-module \
libgles2-mesa-dev \
dbus-x11 \
firefox && \
apt-get clean

# Install fonts
RUN apt-get update && apt-get install -y --no-install-recommends \
fonts-wqy-microhei && \
apt-get clean

CMD ["firefox"]

To build the Docker image, please run the following command.

1
$ docker build -f firefox.Dockerfile -t firefox:24.04 .

To start Firefox from the Docker container, please run the following command.

1
2
3
$ xhost +
$ docker run -it --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix firefox:24.04
$ xhost -
Firefox Launched from Docker Container

References

Firefox Installation In Ubuntu 24.04 Docker Images

https://leimao.github.io/blog/Ubuntu-2404-Docker-Firefox-Installation/

Author

Lei Mao

Posted on

02-28-2025

Updated on

02-28-2025

Licensed under


Comments