Skip to content

Instantly share code, notes, and snippets.

@lemanschik
Created September 20, 2025 06:51
Show Gist options
  • Select an option

  • Save lemanschik/6a08a97530da01c034fa3d5b399c3189 to your computer and use it in GitHub Desktop.

Select an option

Save lemanschik/6a08a97530da01c034fa3d5b399c3189 to your computer and use it in GitHub Desktop.
Hyperland

Of course. Exposing a full Wayland compositor like Hyprland from inside a Docker container is an advanced and interesting challenge. It goes against Docker's typical use case of isolating server applications, as it requires deep access to the host's hardware (GPU, input devices) and a way to stream the graphical output.

This is a great educational exercise in understanding container isolation and how to selectively break it for specific purposes like testing a desktop environment. I will guide you through the concepts and a practical, safe example.

Disclaimer: This process involves giving the Docker container privileged access to your host's hardware devices (/dev/dri, /dev/input). This significantly reduces the security and isolation benefits of Docker. Only run trusted images with these flags.

The Core Challenges

  1. Graphics Hardware Access: Hyprland needs to communicate directly with the GPU to render frames. A standard Docker container has no access to /dev/dri (Direct Rendering Infrastructure).
  2. Input Device Access: To control Hyprland with your keyboard and mouse, the container needs access to the host's input devices, typically found at /dev/input.
  3. Displaying the Output ("Exposing"): This is the main part of your question. Since the container doesn't have a physical screen, you can't just "run" Hyprland. You need a way to see and interact with it. The most robust and container-friendly method is to use a VNC (Virtual Network Computing) server.

The strategy will be:

  • Run Hyprland inside the container using a "headless" backend.
  • Run a Wayland-native VNC server (wayvnc) inside the same container.
  • wayvnc will "capture" the Hyprland session and stream it over the network.
  • You will connect to this stream from your host machine using a VNC client.

Step-by-Step Guide: Hyprland in Docker via VNC

Here is a complete example using an Arch Linux base image, as it's a common platform for Hyprland.

1. Project Structure

Create a new directory for your project and create two files inside it: Dockerfile and start.sh.

hyprland-docker/
├── Dockerfile
└── start.sh

2. The start.sh Script

This script will be the entry point for our container. It sets up the environment and starts both the VNC server and Hyprland.

start.sh

#!/binbash

# Set up the runtime directory for Wayland
export XDG_RUNTIME_DIR=/tmp/xdg
mkdir -p "$XDG_RUNTIME_DIR"
chmod 0700 "$XDG_RUNTIME_DIR"

# Start the Wayland VNC server in the background
# It will create a Wayland socket for Hyprland to connect to.
# Listen on all interfaces (0.0.0.0) on port 5900.
wayvnc 0.0.0.0 5900 &

# Wait a moment for wayvnc to initialize and create the socket
sleep 1

# Start Hyprland
# It will automatically detect and use the Wayland socket created by wayvnc.
# This makes wayvnc the "display" for Hyprland.
exec Hyprland

Now, make this script executable:

chmod +x start.sh

3. The Dockerfile

This file defines how to build the container image. It installs all the necessary dependencies, including Hyprland, a terminal, and the wayvnc server.

Dockerfile

# Use an Arch Linux base image
FROM archlinux:latest

# Update the system and install necessary packages
# We need:
# - hyprland: The compositor itself
# - wayvnc: The VNC server that provides the Wayland backend
# - kitty: A terminal to run inside Hyprland
# - base-devel: For building things if needed
# - git: For potential package builds from AUR
RUN pacman -Syu --noconfirm && \
    pacman -S --noconfirm \
    hyprland \
    wayvnc \
    kitty \
    base-devel \
    git \
    wget

# Create a non-root user to run Hyprland
# Running GUI applications as root is a bad practice
RUN useradd -m -s /bin/bash user
USER user
WORKDIR /home/user

# Copy the start script into the container
COPY start.sh /home/user/start.sh

# Set the entrypoint to our script
ENTRYPOINT ["/home/user/start.sh"]

4. Build the Docker Image

Navigate to your hyprland-docker directory in your terminal and run the build command:

docker build -t hyprland-vnc .

This will take a few minutes as it downloads the base image and installs all the packages.

5. Run the Docker Container

This is the most critical step. You need to provide the correct flags to give the container access to your hardware.

docker run --rm -it \
    --name hyprland-session \
    -p 5900:5900 \
    --device=/dev/dri:/dev/dri \
    --device=/dev/input:/dev/input \
    --group-add video \
    --group-add input \
    hyprland-vnc

Let's break down these flags:

  • --rm -it: Runs the container in interactive mode and removes it when you stop it.
  • -p 5900:5900: Exposes the container's port 5900 (where wayvnc is listening) to your host machine's port 5900.
  • --device=/dev/dri:/dev/dri: Grants the container direct access to your GPU rendering device.
  • --device=/dev/input:/dev/input: Grants the container direct access to your keyboard, mouse, etc.
  • --group-add video & --group-add input: Adds the container's user to the correct groups on the host to ensure it has permission to use these devices.

After running this command, your terminal will show the output from Hyprland starting up inside the container. It is now running and waiting for a VNC connection.

6. Connect with a VNC Client

On your host machine (the same one running Docker), open a VNC client (e.g., Remmina, TigerVNC, Vinagre).

  • Connect to the address: localhost:5900 or 127.0.0.1:5900.
  • You should now see a black screen, which is your Hyprland session!

Press your Super (Windows) key + Enter to open kitty (the terminal we installed). You can now interact with Hyprland as if it were running natively, but it's all happening inside the isolated container.

To stop the session, simply press Ctrl+C in the terminal where you ran the docker run command.

This setup provides a powerful way to test different Hyprland configurations, develop Wayland applications, or experiment with a desktop environment without affecting your main host system.

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