Skip to content

Instantly share code, notes, and snippets.

@techieshark
Last active January 10, 2026 01:27
Show Gist options
  • Select an option

  • Save techieshark/e80949ab002d28c0d99f98dc9f0f7218 to your computer and use it in GitHub Desktop.

Select an option

Save techieshark/e80949ab002d28c0d99f98dc9f0f7218 to your computer and use it in GitHub Desktop.
surf browser on mac

Running Surf on macOS via Docker

This guide provides instructions on how to build and run the surf browser on macOS using Docker and XQuartz. This method encapsulates all of surf's Linux dependencies within a Docker container.

Prerequisites

  1. surf source code.
  2. Docker: Ensure you have Docker installed and the daemon is running. You can get it from the Docker website.
  3. XQuartz: This is an X11 server for macOS, which is required to display GUI applications running inside the container.
    • Download and install it from the XQuartz website.
    • After installation, you must log out and log back in for it to function correctly.

Configuration

0. Surf source

git clone git://git.suckless.org/surf

then add these docker files to the code.

1. Configure XQuartz

Before running the application, you need to configure XQuartz to allow network connections:

  1. Open XQuartz.
  2. Go to XQuartz -> Preferences in the menu bar.
  3. Navigate to the Security tab.
  4. Ensure that the checkbox for "Allow connections from network clients" is checked.
  5. Restart XQuartz for the setting to take effect.

2. Authorize Host Connection

Open your regular macOS terminal (e.g., Terminal.app or iTerm2) and run the following command. This command allows your Docker container to connect to the XQuartz server on your host machine.

/opt/X11/bin/xhost +127.0.0.1

Note: If you are using a different IP for your docker host, you may need to change this.

Build and Run

The project includes a Dockerfile that automates the build process.

1. Build the Docker Image

Navigate to the project's root directory in your terminal and run the following command to build the image:

docker build -t surf-browser .

2. Run the Container

Once the image is built, run the following command to start the surf browser:

docker run --rm -e DISPLAY="host.docker.internal:0" surf-browser
  • --rm: Automatically removes the container when you close the application.
  • -e DISPLAY="host.docker.internal:0": This tells the application inside the container to send its display to the XQuartz server running on your Mac. host.docker.internal is a special DNS name provided by Docker that resolves to your host machine's IP.

The surf browser window should now appear on your screen, open to the suckless.org homepage.

# Use a standard Debian image as the base
FROM debian:bullseye
# Install build-time and run-time dependencies
RUN apt-get update && apt-get install -y \
build-essential \
pkg-config \
libgtk-3-dev \
libwebkit2gtk-4.0-dev \
libgcr-3-dev \
dmenu \
ca-certificates \
x11-utils \
--no-install-recommends
# Copy the application source code into the container
WORKDIR /app
COPY . .
# Compile the application
RUN make
# Set the default command to run surf
CMD ["./surf", "suckless.org"]
# Build stage
FROM alpine:latest AS builder
RUN apk add --no-cache \
build-base \
gtk+3.0-dev \
webkit2gtk-4.1-dev \
gcr-dev \
glib-dev \
pkgconfig
WORKDIR /app
COPY . .
RUN sed -i 's/webkit2gtk-4\.0/webkit2gtk-4.1/g' config.mk Makefile && \
sed -i 's/webkit2gtk-web-extension-4\.0/webkit2gtk-web-extension-4.1/g' config.mk Makefile && \
make
# Runtime stage
FROM alpine:latest
RUN apk add --no-cache \
gtk+3.0 \
webkit2gtk-4.1 \
gcr \
glib \
dmenu \
xprop \
ca-certificates \
mesa-dri-gallium \
mesa-gl \
font-dejavu
COPY --from=builder /app/surf /usr/local/bin/
COPY --from=builder /app/webext-surf.so /usr/local/lib/surf/
CMD ["surf", "suckless.org"]

The alpine 2-step version is a bit smaller ("small" tag):

REPOSITORY          TAG          IMAGE ID       CREATED             SIZE
surf-browser        small        ec1163fefc1b   16 minutes ago      639MB
surf-browser        latest       e407304dedb1   About an hour ago   1.14GB

Run these like:

docker run --rm -it -e DISPLAY=host.docker.internal:0 surf-browser

docker run --rm -it -e DISPLAY=host.docker.internal:0 surf-browser:small

In 'surf', use Ctrl-G then type a URL to go to. There is no UI. For more controls, grep MOD * in the source code.

Usual disclaimer: I make no warranty that any of this works or is even a good idea. I just tried out 'surf' today and sharing this here in case it helps others.

Qutebrowser is another good option on Mac (brew install qutebrowser). See https://qutebrowser.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment