Prerequisites
Before you begin, make sure you’ve completed the prerequisites:- Docker installed and running
- Display access enabled with
xhost +local:docker - User added to docker group (optional but recommended)
Quick Start
Clone or download the repository
Get the Raylib Container files from GitHub:Or download the repository as a ZIP file and extract it.
Build the Docker image
Build the container image with Raylib pre-compiled:The build process:
This step will take several minutes as it compiles Raylib from source. The image is built using a multi-stage process with Alpine Linux for minimal size.
- Installs build dependencies (GCC, CMake, Mesa, X11 libraries)
- Clones the latest Raylib from GitHub
- Compiles Raylib with optimizations
- Creates a minimal runtime image with only necessary components
Run the container with hardware acceleration
Start the container with GPU access for best performance:What these flags do:
-it- Interactive mode with terminal--rm- Auto-remove container on exit-e DISPLAY=$DISPLAY- Forward display to your screen-v /tmp/.X11-unix:/tmp/.X11-unix- Mount X11 socket-v ./user_code:/app/user_code- Mount your code directory--device /dev/dri:/dev/dri- GPU access for hardware acceleration
Alternative: Software rendering (if needed)
If hardware acceleration doesn’t work, use software rendering:
Verify graphics connection
Once inside the container, test the display connection:A window with eyes that follow your mouse should appear. If you see the window, your graphics setup is working correctly!Close the xeyes window by clicking the X button or pressing Ctrl+C in the terminal.
Compile the example game
Navigate to the user code directory and compile the included example:Compiler flags explained:
my_game.c- Your source code file-o my_game- Output executable name-lraylib- Link Raylib library-lGL -lm -lpthread -ldl -lrt -lX11- Required system libraries
The Example Game Code
The includedmy_game.c demonstrates a basic Raylib window:
my_game.c
Next Steps
Now that you have Raylib Container running, here’s what to explore next:Learn Development Workflow
Understand how to develop games inside the container
Compilation Guide
Learn advanced compilation techniques and flags
Example Walkthrough
Deep dive into the example game code
Platform-Specific Setup
Platform guides for Linux, macOS, and Windows
Development Workflow
Here’s the typical development cycle:- Edit code on your host system in the
user_code/directory - Changes sync automatically to the container via volume mount
- Compile inside the container using GCC
- Run and test your game in the container
- Iterate - repeat the process as you develop
Common Issues
Container won't start - Permission denied error
Container won't start - Permission denied error
You may need to run Then log out and log back in for the change to take effect.
sudo docker ... if you haven’t added your user to the docker group:Window doesn't appear - Display error
Window doesn't appear - Display error
Make sure you ran This command needs to be run in each new graphical session.
xhost +local:docker before starting the container:Graphics errors - DRI/MESA failures
Graphics errors - DRI/MESA failures
Try software rendering instead of hardware acceleration:
Compilation errors - Library not found
Compilation errors - Library not found
Make sure you’re using all required library flags:The order and inclusion of all flags is important for successful linking.
Using Pre-built Images
Instead of building locally, you can pull the pre-built image from Docker Hub:The pre-built image from Docker Hub may not have the absolute latest Raylib version. Building locally ensures you get the most recent Raylib release.