I wanted to experiment with developing a game using the Bevy Engine, but didn’t want to install a bunch of dependencies on my computer. I wanted to keep things contained in a VS Code Dev Container. The tricky part was getting Wayland support working for the demos.
This required crafting a slightly custom Dockerfile and devcontainer.json.
First, I enabled Wayland socket binding in vscode by going into Settings and enabling “Mount Wayland Socket”:
Here’s the Dockerfile I’m using, although it has several unnecessary packages for just adding Wayland support. Several of these are for x11.
.devcontainer/Dockerfile
FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye
# Install the necessary system libraries
RUN apt-get update && apt-get install -y \
pkg-config \
libasound2-dev \
libudev-dev \
mesa-utils \
vulkan-tools \
libwayland-dev \
libxkbcommon-dev \
libvulkan1 \
libvulkan-dev \
libegl1-mesa-dev \
libgles2-mesa-dev \
libx11-dev \
libxcursor-dev \
libxrandr-dev \
libxi-dev \
libxrandr-dev \
libxcb1-dev \
libxcb-icccm4-dev \
libxcb-image0-dev \
libxcb-keysyms1-dev \
libxcb-randr0-dev \
libxcb-shape0-dev \
libxcb-xfixes0-dev \
libxcb-xkb-dev \
libegl1-mesa \
libgl1-mesa-glx \
libgl1-mesa-dri \
libglu1-mesa-dev \
libglu1-mesa \
libgles2-mesa \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
.devcontainer/devcontainer.json
{
"name": "Rust",
"build": {
"dockerfile":"Dockerfile",
"context": "."
},
"mounts": [
"source=/dev/dri,target=/dev/dri,type=bind",
"source=/dev/snd,target=/dev/snd,type=bind",
"source=/etc/asound.conf,target=/etc/asound.conf,type=bind",
],
"runArgs": [
"--privileged",
// Had to add some groups for dri and snd access
"--group-add", "17",
"--group-add", "26",
"--group-add", "303"
]
}
That should be enough to get Wayland access inside the container. x11 apps should work too.
Modify Cargo.toml to include Wayland support in Bevy:
[dependencies]
bevy = { version = "0.11", features = ["wayland"] }