Overview
Linux provides native support for Docker containers with graphical output through X11 or Wayland. This guide covers the complete setup process for running the Raylib Container on Linux systems.Prerequisites
Before using the container, you need to configure your host system to allow graphical applications from the container to run and manage Docker withoutsudo.
This guide assumes you have Docker already installed on your Linux system. If not, install it from your distribution’s package manager or from the official Docker website.
Setup Steps
Enable Display Access
Allow local Docker containers to connect to your graphics server (X11 or Wayland via XWayland):To make this persistent, add the command to your shell profile:
Add User to Docker Group
Adding your user to the To verify the group membership:
docker group removes the need to use sudo for Docker commands:Depending on your Linux distribution configuration, there might be situations where using
sudo is still necessary for some tasks, even if the user is a member of the docker group (for example, when interacting with the graphical interface).Running the Container
With Hardware Acceleration (Recommended)
This option uses your host system’s GPU for better performance:-it: Starts the container in interactive mode with a terminal attached--rm: Automatically removes the container when it exits-e DISPLAY=$DISPLAY: Passes the host’sDISPLAYenvironment variable to the container-v /tmp/.X11-unix:/tmp/.X11-unix: Mounts the host’s X11 socket for graphical communication-v ./user_code:/app/user_code: Mounts your code directory into the container--device /dev/dri:/dev/dri: Maps the Direct Rendering Infrastructure devices for GPU access
With Software Rendering (Fallback)
Use this option if hardware acceleration doesn’t work. Performance will be lower:Hardware Acceleration on Linux
Understanding GPU Access
The/dev/dri device provides Direct Rendering Infrastructure access, allowing containers to use your GPU:
card0, renderD128, etc.
Common GPU Drivers
Intel Graphics
Intel Graphics
Modern Intel integrated graphics use the
iris driver (newer) or i965 driver (older).The container should work out-of-the-box with Intel graphics when using the --device /dev/dri:/dev/dri flag.AMD Graphics
AMD Graphics
AMD graphics use the
radeonsi or amdgpu driver.Ensure your host system has the Mesa drivers installed. The container will use them through the mounted DRI devices.NVIDIA Graphics
NVIDIA Graphics
NVIDIA requires additional setup with the NVIDIA Container Toolkit.If hardware acceleration fails with NVIDIA, fall back to software rendering with
-e LIBGL_ALWAYS_SOFTWARE=1.Verifying Graphics Connection
Once inside the container, test the graphics connection:Reverting Configuration
If you need to undo the changes made during setup:Security Considerations
If you accidentally changed the permissions, restore them:Troubleshooting
Error: Cannot connect to the Docker daemon
Error: Cannot connect to the Docker daemon
Full error:
docker: Cannot connect to the Docker daemon... Permission denied.Solution: You likely haven’t added your user to the docker group or didn’t log out/log in after adding them. Try using sudo docker ... or follow the user group setup step above.Window doesn't appear / cannot open display
Window doesn't appear / cannot open display
Full error:
Error: cannot open display: :0Solution:- Check that you ran
xhost +local:dockerin the current host graphical session - Verify the
DISPLAYvariable is being passed correctly (-e DISPLAY=$DISPLAY) - Ensure you’re running from a graphical session, not SSH or TTY
MESA errors / Failed to query drm device
MESA errors / Failed to query drm device
Full error:
MESA: error: Failed to query drm device., glx: failed to create dri3 screen, failed to load driver: iris/radeon/etc.Solution: Hardware acceleration isn’t working. Ensure the --device /dev/dri:/dev/dri flag was used. If it still fails, try software rendering with -e LIBGL_ALWAYS_SOFTWARE=1.Error: invalid reference format
Error: invalid reference format
Full error:
docker: invalid reference formatSolution: Check if the image name (raylib_container) is spelled correctly in the docker run command and that the image actually exists. Verify with docker images.Next Steps
Build the Image
Learn how to build the Raylib Container image
Quick Start
Create your first Raylib project