📄 docker-image-firefox-browser-on-alpine | home

Run Firefox Browser in Docker on Alpine Linux

guest@techdiy:~$

Firefox Browser - Docker Image Based on Alpine

This Docker image provides a lightweight and secure environment to run the "Firefox Browser" Based on "Alpine Linux", it is designed for users who prioritize speed and efficiency while maintaining privacy and security while browsing the web.

Requirements:

1. Podman (recommended) - In the .sh file below `podman` is used instead of `docker`.

Why Podman?: It offers a DAEMONLESS architecture and supports running containers WITHOUT root privileges, which can improve both security and system stability. Since its CLI is largely compatible with Docker, most commands can be used without modification.

2. Docker (compatible) - Ensure to replace `podman` with `docker` in the .sh file if you want to use it instead.

3. X11 Server -- You need to have an **X11** server running for the graphical interface.

⚠️ It does not work on Wayland !

(to check what you using - run: `echo $XDG_SESSION_TYPE` on Linux)

⚠️ Tested on KDE Plasma (Linux). If you encounter issues, you may need to install additional package(s) for your desktop environment. Just follow the error message for guidance. Windows, macOS, and other operating systems have not been tested !_


Usage:

👣 Create a folder firefox-alpine

👣 Create two files in that folder: Dockerfile & run-firefox.sh with the code below...

Dockerfile:
# Use the Alpine base image. DON'T use later than alpine:3:22, Firefox fails to launch !
FROM alpine:3.22

# Install Firefox, X11, and other necessary dependencies
RUN apk update && apk add --no-cache \
    firefox \
    dbus \
    ttf-dejavu \
    font-noto \
    xvfb \
    xauth \
    bash \
    ffmpeg \
    pulseaudio \
    mesa-gl \
    dbus-glib

# Install glibc from sgerrand, ensuring there is no conflict with nsswitch.conf
RUN apk --no-cache add --virtual .build-deps curl ca-certificates && \
    curl -Lo /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
    curl -Lo glibc-2.35-r0.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r0/glibc-2.35-r0.apk && \
    # Backup existing nsswitch.conf to avoid conflict
    cp /etc/nsswitch.conf /etc/nsswitch.conf.bak || true && \
    apk add --force-overwrite glibc-2.35-r0.apk && \
    # Restore the original nsswitch.conf if needed
    cp /etc/nsswitch.conf.bak /etc/nsswitch.conf || true && \
    rm -f glibc-2.35-r0.apk && \
    apk del .build-deps

# Add a non-root user for running Firefox
RUN adduser -D nonrootuser

# Switch to the non-root user
USER nonrootuser

# Set the environment variable to forward the X display
ENV DISPLAY=:99

# Create a startup script to run Firefox with Xvfb
RUN echo -e '#!/bin/bash\n\
Xvfb :99 -screen 0 1280x1024x16 &\n\
firefox' > /home/nonrootuser/start-firefox.sh

# Make the script executable
RUN chmod +x /home/nonrootuser/start-firefox.sh

# Set the entrypoint to start the script
ENTRYPOINT ["/bin/bash", "/home/nonrootuser/start-firefox.sh"]
	
run-firefox.sh:
#!/bin/bash

# Build the Podman image for Firefox on Alpine
podman build -t dockerfos/firefox-alpine .

# Allow local Podman rootless user to access the X server
xhost +local:$(id -un)

# PulseAudio environment (sound support)
PULSE_SERVER="unix:/run/user/$(id -u)/pulse/native"
PULSE_SOCKET="/run/user/$(id -u)/pulse/native"
PULSE_COOKIE="$HOME/.config/pulse/cookie"

# Run Firefox container with:
# - X11 forwarding
# - PulseAudio sound
# - Rootless slirp networking
podman run -it --rm \
  --network=slirp4netns \
  -e DISPLAY=$DISPLAY \
  -e PULSE_SERVER="$PULSE_SERVER" \
  -v /tmp/.X11-unix:/tmp/.X11-unix:rw \
  -v "$PULSE_SOCKET:$PULSE_SOCKET:rw" \
  -v "$PULSE_COOKIE:/home/nonrootuser/.config/pulse/cookie:ro" \
  dockerfos/firefox-alpine

# Revoke X server access
xhost -local:$(id -un)
	

👣 Make run-firefox.sh executable:

chmod +x run-firefox.sh

👣 No need to build the image - just run the script:

./run-firefox.sh

💡 Security Considerations:

• This container is designed to run in a sandboxed environment with minimal exposure to the host system.

• It's recommended to run this image using non-privileged user permissions and limit access to sensitive directories.

⚠️ Disclaimer:

This Docker image is provided as-is, without any warranties or guarantees of any kind. Use of this image is entirely at your own risk.


🐙 Github: See on Github↗️

🦊 Gitlab: See on Gitlab↗️