sudo snap install lxd
sudo lxc network create lxcnet --type=bridge ipv4.address=10.0.0.1/24 ipv4.nat=true
sudo lxc storage create storagepool zfs
sudo lxc profile create desktop
sudo lxc profile edit desktop
Profile file contents:
name: desktop
description: Container with GUI, graphics card and audio support
devices:
PASocket0:
bind: container
connect: unix:/run/myusername/1000/pulse/native
gid: '1000'
listen: unix:/home/ubuntu/pulse-socket
mode: '0777'
security.gid: '1000'
security.uid: '1000'
type: proxy
uid: '1000'
X0:
bind: container
connect: unix:/tmp/.X11-unix/X1
listen: unix:/tmp/.X11-unix/X0
security.gid: '1000'
security.uid: '1000'
type: proxy
gpu0:
type: gpu
config:
boot.autostart: 'false'
environment.DISPLAY: ':0'
environment.PULSE_SERVER: unix:/home/ubuntu/pulse-socket
nvidia.driver.capabilities: graphics, compute, display, utility, video
nvidia.runtime: 'true'
This profile makes the following assumptions (you need to adapt it to fit your setup):
- Host and container are
Ubuntu 24.04
. - Host window system is
X11
. - Host X11 socket file name is
X1
(checkls /tmp/.X11-unix/
and replaceX1
indevices.X0.connect
with what command gave to you). - Host graphics card is
nvidia
. - Host user name is
myusername
(replace it with yours indevices.PASocket0.connect
line). - Host User Identifier (UID) is
1000
. - Host Group Identifier (GID) is
1000
.
sudo lxc launch ubuntu:24.04 mycontainer --profile=desktop --storage=storagepool --network=lxcnet
sudo lxc exec mycontainer -- bash
apt update
apt install libgl1 pulseaudio --yes
In this exaple we are trying to create a desktop shortcut for the game Warzone 2100, from container warzone2100
.
Create .desktop
file:
tee /tmp/warzone2100.desktop > /dev/null << ENDSEQ
#!/usr/bin/env xdg-open
[Desktop Entry]
Type=Application
Exec=pkexec sh -c "lxc start warzone2100; lxc exec warzone2100 -- /usr/games/warzone2100.real && lxc stop warzone2100"
Terminal=false
Name=Warzone 2100
ENDSEQ
Add .desktop file to applications menu:
sudo desktop-file-install /tmp/warzone2100.desktop