Quick Start
Start an interactive container with graphics support:- Interactive terminal access
- Auto-removal when you exit
- Graphics display connection
- Your code directory mounted
- Hardware-accelerated graphics
Docker Run Flags Explained
Understanding each flag in thedocker run command:
-it: Interactive Terminal
What does -it do?
What does -it do?
This is actually two flags combined:
-i(interactive): Keep STDIN open even if not attached-t(tty): Allocate a pseudo-TTY terminal
--rm: Auto-Remove Container
Without
--rm, each time you run the container, Docker creates a new stopped container that persists on disk. You’d need to manually remove them with docker rm.-e DISPLAY=$DISPLAY: Display Environment
DISPLAY environment variable to the container, telling graphical applications which screen to use.
What this does:
$DISPLAYon the host typically contains:0or:1(your display number)- The container uses this to connect to the X11 server
- Without this, graphical windows won’t know where to appear
-v /tmp/.X11-unix:/tmp/.X11-unix: X11 Socket
Understanding X11 Socket Mounting
Understanding X11 Socket Mounting
/tmp/.X11-unix: Directory containing Unix domain sockets for X11- The format is
-v <host-path>:<container-path> - This creates a bidirectional communication channel for graphics
- Required for any GUI application to display windows
-v ./user_code:/app/user_code: Code Volume
user_code directory to /app/user_code inside the container.
Key behaviors:
- Files are synchronized between host and container in real-time
- Changes made inside the container persist on your host
- If
./user_codedoesn’t exist, Docker creates it automatically - You can use an absolute path instead:
-v /path/to/my/code:/app/user_code
--device /dev/dri:/dev/dri: GPU Access
/dev/dri/card0: Primary GPU device/dev/dri/renderD128: Render node for GPU computation- Additional cards/nodes if you have multiple GPUs
Run Scenarios
- Hardware Acceleration
- Software Rendering
- Custom Code Path
- Multiple Volumes
Recommended for best performanceUse when:
- Your system has a working GPU with proper drivers
- You need maximum graphics performance
- Running complex 3D games or high-framerate applications
Container Lifecycle Management
Interactive Mode vs Detached Mode
Interactive Mode (recommended for development):Detached mode is useful for long-running development sessions where you want to attach/detach multiple times without stopping the container.
Starting and Stopping
Exit Interactive Session
Inside the container, type:With
--rm, this removes the container automatically.Persistent vs Ephemeral Containers
Ephemeral (with--rm):
- Container is deleted on exit
- Any changes inside (except volumes) are lost
- Clean and recommended for most use cases
--rm):
- Container persists after exit
- Can be restarted with
docker start -i my_raylib - System packages you install remain across sessions
- Must be manually removed with
docker rm my_raylib
Working Inside the Container
Once inside the container, you’ll be in the/app/user_code directory:
Verifying Graphics Connection
Compiling Code
Navigate to your code and compile:Running Programs
Environment Variables
Common environment variables you can pass:| Variable | Purpose | Example |
|---|---|---|
DISPLAY | X11 display target | -e DISPLAY=$DISPLAY |
LIBGL_ALWAYS_SOFTWARE | Force software rendering | -e LIBGL_ALWAYS_SOFTWARE=1 |
LIBGL_DEBUG | Enable OpenGL debugging | -e LIBGL_DEBUG=verbose |
Troubleshooting
Error: 'Cannot connect to the Docker daemon'
Error: 'Cannot connect to the Docker daemon'
Cause: Docker daemon isn’t running or you don’t have permissions.Solution:
Error: 'cannot open display'
Error: 'cannot open display'
Cause: X11 access not configured.Solution:
Error: 'invalid reference format'
Error: 'invalid reference format'
Cause: Image name is misspelled or image doesn’t exist.Solution:
Graphics errors (DRI/Mesa/GLX)
Graphics errors (DRI/Mesa/GLX)
Cause: Hardware acceleration not working.Solution:
Switch to software rendering mode. See Graphics Options.
Next Steps
Graphics Configuration
Learn about hardware acceleration and rendering options
Development Workflow
Start building games with Raylib