Skip to content

Instantly share code, notes, and snippets.

@stueja
Last active August 14, 2024 07:46
Show Gist options
  • Save stueja/447bd3bc0d510a0a7e50f9f1ef58ad75 to your computer and use it in GitHub Desktop.
Save stueja/447bd3bc0d510a0a7e50f9f1ef58ad75 to your computer and use it in GitHub Desktop.
GUI application via Wayland from Ubuntu LXD container on Arch Linux host

GUI application via Wayland from Ubuntu LXD container on Arch Linux host

Sources

Install Wayland in Ubuntu: https://askubuntu.com/questions/832509/how-to-install-wayland-on-ubuntu-16-04-lts

Start X applications in a container: https://blog.simos.info/how-to-run-graphics-accelerated-gui-apps-in-lxd-containers-on-your-ubuntu-desktop/

Wayland in container: https://unix.stackexchange.com/questions/330366/how-can-i-run-a-graphical-application-in-a-container-under-wayland/359244#359244

UID/GID mapping: https://lists.linuxcontainers.org/pipermail/lxc-users/2016-July/012047.html

install LXD

sudo pacman -S lxd arch-install-scripts
wget https://aur.archlinux.org/cgit/aur.git/snapshot/lxd.tar.gz
tar xvf lxd.tar.gz
cd lxd
makepkg --syncdeps

systemctl start lxd.service

map UID/GID

# auf dem Host
echo "root:$UID:1" | sudo tee -a /etc/subuid /etc/subgid

cat /etc/subuid

# auf dem Host
cat /etc/subuid /etc/subgid 
user:100000:65536
lxd:165536:65536
root:165536:65536
root:1000:1

launch container

# auf dem Host
lxc launch ubuntu:x guiapps

Configure lxd and restart container

# auf dem Host
lxc config set guiapps raw.idmap "both $UID 1000"
lxc restart guiapps

home directory in rootfs

# auf dem Host
[user@host ~]# sudo ls -al /var/lib/lxd/containers/guiapps/rootfs/home/ubuntu/
total 31
drwxr-xr-x 7 jan    jan    3488 31. Dez 14:04 .
drwxr-xr-x 3 165536 165536 3488 31. Dez 12:45 ..
drwxr-xr-x 2 165536 165536 3488 31. Dez 13:45 1000
-rw------- 1 jan    jan     570 31. Dez 14:06 .bash_history
-rw-r--r-- 1 jan    jan     220  1. Sep 2015  .bash_logout
-rw-r--r-- 1 jan    jan    3771  1. Sep 2015  .bashrc
drwxr-xr-x 4 jan    jan    3488 31. Dez 14:05 .cache
drwxr-xr-x 2 jan    jan    3488 31. Dez 14:04 Desktop
drwx------ 5 jan    jan    3488 31. Dez 14:04 .mozilla
-rw-r--r-- 1 jan    jan     778 31. Dez 13:50 .procode
drwx------ 2 jan    jan    3488 31. Dez 12:45 .ssh
-rw-r--r-- 1 jan    jan       0 31. Dez 13:41 .sudo_as_admin_successful

Wayland in Container

# im Container
# xwayland hier mit kleinem X
sudo apt-get update && sudo apt-get install xwayland weston x11-apps mesa-utils



# im Container
sudo apt-get update && sudo apt-get install xwayland weston x11-apps mesa-utils
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]                             
Hit:3 http://security.ubuntu.com/ubuntu xenial-security InRelease                                    
Get:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 204 kB in 0s (301 kB/s)                              
Reading package lists... Done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  colord colord-data dconf-gsettings-backend dconf-service fontconfig fontconfig-config fonts-dejavu-core libavahi-client3 libavahi-common-data libavahi-common3
  libboost-codesystem1.58.0 libboost-system1.58.0 libcairo2 libcapnp-0.5.3 libcolord2 libcolorhug2 libdatrie1 libdconf1 libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2
  libdrm-radeon1 libegl1-mesa libepoxy0 libevdev2 libexif12 libfontconfig1 libfontenc1 libgbm1 libgd3 libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa libgles2-mesa
  libgphoto2-6 libgphoto2-l10n libgphoto2-port12 libgraphite2-3 libgudev-1.0-0 libgusb2 libharfbuzz0b libice6 libieee1284-3 libinput-bin libinput10 libjbig0
  libjpeg-turbo8 libjpeg8 liblcms2-2 libllvm4.0 libltdl7 libmirclient9 libmircommon7 libmircore1 libmirprotobuf3 libmtdev1 libpango-1.0-0 libpangocairo-1.0-0
  libpangoft2-1.0-0 libpciaccess0 libpixman-1-0 libprotobuf-lite9v5 libsane libsane-common libsensors4 libsm6 libthai-data libthai0 libtiff5 libtxc-dxtn-s2tc0 libvpx3
  libwacom-bin libwacom-common libwacom2 libwayland-client0 libwayland-cursor0 libwayland-egl1-mesa libwayland-server0 libx11-xcb1 libxaw7 libxcb-composite0
  libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-render0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcb-xkb1 libxcursor1 libxdamage1 libxfixes3
  libxfont1 libxkbcommon0 libxkbcode1 libxmu6 libxpm4 libxrender1 libxshmfence1 libxt6 libxxf86vm1 x11-common x11-xkb-utils xfonts-base xfonts-encodings xfonts-utils
  xserver-common
Suggested packages:
  colord-sensor-argyll libgd-tools gphoto2 liblcms2-utils avahi-daemon hplip libsane-extras sane-utils lm-sensors xfs | xserver
The following NEW packages will be installed:
  colord colord-data dconf-gsettings-backend dconf-service fontconfig fontconfig-config fonts-dejavu-core libavahi-client3 libavahi-common-data libavahi-common3
  libboost-codesystem1.58.0 libboost-system1.58.0 libcairo2 libcapnp-0.5.3 libcolord2 libcolorhug2 libdatrie1 libdconf1 libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2
  libdrm-radeon1 libegl1-mesa libepoxy0 libevdev2 libexif12 libfontconfig1 libfontenc1 libgbm1 libgd3 libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa libgles2-mesa
  libgphoto2-6 libgphoto2-l10n libgphoto2-port12 libgraphite2-3 libgudev-1.0-0 libgusb2 libharfbuzz0b libice6 libieee1284-3 libinput-bin libinput10 libjbig0
  libjpeg-turbo8 libjpeg8 liblcms2-2 libllvm4.0 libltdl7 libmirclient9 libmircommon7 libmircore1 libmirprotobuf3 libmtdev1 libpango-1.0-0 libpangocairo-1.0-0
  libpangoft2-1.0-0 libpciaccess0 libpixman-1-0 libprotobuf-lite9v5 libsane libsane-common libsensors4 libsm6 libthai-data libthai0 libtiff5 libtxc-dxtn-s2tc0 libvpx3
  libwacom-bin libwacom-common libwacom2 libwayland-client0 libwayland-cursor0 libwayland-egl1-mesa libwayland-server0 libx11-xcb1 libxaw7 libxcb-composite0
  libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-render0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcb-xkb1 libxcursor1 libxdamage1 libxfixes3
  libxfont1 libxkbcommon0 libxkbcode1 libxmu6 libxpm4 libxrender1 libxshmfence1 libxt6 libxxf86vm1 weston x11-common x11-xkb-utils xfonts-base xfonts-encodings
  xfonts-utils xserver-common xwayland
0 upgraded, 110 newly installed, 0 to remove and 0 not upgraded.
Need to get 37.2 MB of archives.
After this operation, 233 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

use graphics hardware acceleration

# auf dem Host
lxc config device add guiapps mygpu gpu
lxc config device set guiapps mygpu uid 1000
lxc config device set guiapps mygpu gid 1000

mount wayland socket

# auf dem Host
# für Wayland
lxc config device add guiapps u1000 disk path=/home/ubuntu/1000 source=/run/user/1000
# für X (xclock etc)
lxc config device add guiapps X0 disk path=/tmp/.X11-unix/X0 source=/tmp/.X11-unix/X0

Container config should look like that:

lxc config show guiapps

architecture: x86_64
config:
  image.architecture: amd64
  image.description: ubuntu 16.04 LTS amd64 (release) (20171221)
  image.label: release
  image.os: ubuntu
  image.release: xenial
  image.serial: "20171221"
  image.version: "16.04"
  raw.idmap: both 1000 1000
  volatile.base_image: 37a7b2fc60a834b0249df4af35e470c8409c51d48b5b097d32d5ca07a86ccda6
  volatile.eth0.hwaddr: 00:16:3e:39:5f:6a
  volatile.eth0.name: eth0
  volatile.idmap.base: "0"
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":true,"Isgid":false,"Hostid":166537,"Nsid":1001,"Maprange":64535},{"Isuid":false,"Isgid":true,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":false,"Isgid":true,"Hostid":166537,"Nsid":1001,"Maprange":64535}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":true,"Isgid":false,"Hostid":166537,"Nsid":1001,"Maprange":64535},{"Isuid":false,"Isgid":true,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":false,"Isgid":true,"Hostid":166537,"Nsid":1001,"Maprange":64535}]'
  volatile.last_state.power: RUNNING
devices:
  X0:
    path: /tmp/.X11-unix/X0
    source: /tmp/.X11-unix/X0
    type: disk
  mygpu:
    gid: "1000"
    type: gpu
    uid: "1000"
  u1000:
    path: /home/ubuntu/1000
    source: /run/user/1000
    type: disk
ephemeral: false
procodes:
- default
stateful: false
description: ""

set some environment variables in container

# im Container (als user)
echo "export XDG_RUNTIME_DIR=/home/ubuntu/1000" >> ~/.profile
echo "export WAYLAND_DISPLAY=wayland-0" >> ~/.profile
echo "export QT_QPA_PLATFORM=wayland" >> ~/.profile
echo "export DISPLAY=:0" >> .profile
. .profile

Test

# im Container
xclock
glxinfo
glxgears

install Firefox

# im Container
sudo apt-get install firefox



sudo apt-get install firefox
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  adwaita-icon-theme at-spi2-core glib-networking glib-networking-common
  glib-networking-services gsettings-desktop-schemas hicolor-icon-theme
  humanity-icon-theme libasound2 libasound2-data libatk-bridge2.0-0
  libatk1.0-0 libatk1.0-data libatspi2.0-0 libcairo-gobject2 libcanberra0
  libcroco3 libcups2 libdbusmenu-glib4 libdbusmenu-gtk4 libgdk-pixbuf2.0-0
  libgdk-pixbuf2.0-common libgtk-3-0 libgtk-3-bin libgtk-3-common
  libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libjson-glib-1.0-0
  libjson-glib-1.0-common libogg0 libproxy1v5 librest-0.7-0 librsvg2-2
  librsvg2-common libsoup-gnome2.4-1 libsoup2.4-1 libstartup-notification0
  libtdb1 libvorbis0a libvorbiscode3 libxcb-util1 libxcomposite1 libxi6
  libxinerama1 libxrandr2 libxtst6 sound-theme-freedesktop ubuntu-mono
  xul-ext-ubufox
Suggested packages:
  fonts-lyx libasound2-plugins alsa-utils libcanberra-gtk0
  libcanberra-pulse cups-common gvfs librsvg2-bin
The following NEW packages will be installed:
  adwaita-icon-theme at-spi2-core firefox glib-networking
  glib-networking-common glib-networking-services gsettings-desktop-schemas
  hicolor-icon-theme humanity-icon-theme libasound2 libasound2-data
  libatk-bridge2.0-0 libatk1.0-0 libatk1.0-data libatspi2.0-0
  libcairo-gobject2 libcanberra0 libcroco3 libcups2 libdbusmenu-glib4
  libdbusmenu-gtk4 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgtk-3-0
  libgtk-3-bin libgtk-3-common libgtk2.0-0 libgtk2.0-bin libgtk2.0-common
  libjson-glib-1.0-0 libjson-glib-1.0-common libogg0 libproxy1v5
  librest-0.7-0 librsvg2-2 librsvg2-common libsoup-gnome2.4-1 libsoup2.4-1
  libstartup-notification0 libtdb1 libvorbis0a libvorbiscode3 libxcb-util1
  libxcomposite1 libxi6 libxinerama1 libxrandr2 libxtst6
  sound-theme-freedesktop ubuntu-mono xul-ext-ubufox
0 upgraded, 51 newly installed, 0 to remove and 0 not upgraded.
Need to get 55.5 MB of archives.
After this operation, 232 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

start Firefox

# im Container
firefox

Create a shortcut for Firefox on the host

# auf dem Host
nano ~/.local/share/applications/lxd-firefox.desktop

[Desktop Entry]
Version=1.0
Name=Firefox in LXD
Comment=Access the Internet through an LXD container
Exec=lxc exec guiapps -- su --login ubuntu firefox %U
Icon=/usr/share/icons/HighContrast/scalable/apps-extra/firefox-icon.svg
Type=Application
Categories=Network;WebBrowser;

chmod +x ~/.local/share/applications/lxd-firefox.desktop

TODO: sound

see also: https://blog.simos.info/how-to-run-graphics-accelerated-gui-apps-in-lxd-containers-on-your-ubuntu-desktop/

@abasty
Copy link

abasty commented Oct 26, 2020

Wonderful article! Many thanks!

@RobertusIT
Copy link

RobertusIT commented Oct 3, 2021

please can you show me how to install it ?

https://github.com/ehough/docker-kodi

I use proxmox, so i wish to use LXC docker container, to install kodi and have audio video output.

@stueja
Copy link
Author

stueja commented Oct 3, 2021

So, this article is about Ubuntu in an LXC container on a system I have shell access to. I used that a long time ago for a test.
You are asking about Kodi in a docker container with proxmox access.
Sorry, I cannot help here. But maybe someone else reading this.

@osamuaoki
Copy link

FYI: I wrote "YAML to allow IPCs for Wayland + X + sounds" for Debian bookworm as a part of learning experience. It also covers sound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment