Running GUI applications in LXD on Fedora 26

Create container:

[iaroki@fedora ~]$ lxc launch images:debian/stretch chrome

Install needed tools:

[iaroki@fedora ~]$ lxc exec chrome bash
root@chrome:~# adduser iaroki
root@chrome:~# apt update
root@chrome:~# apt install x11-apps mesa-utils alsa-utils

Map UID and GID ramges:

[iaroki@fedora ~]$ echo "root:1000:1" | sudo tee -a /etc/subuid /etc/subgid

Set UID/GUID ranges for container:

[iaroki@fedora ~]$ lxc config set chrome raw.idmap "both $UID 1000"
[iaroki@fedora ~]$ lxc restart chrome

Mount X11 socket and .Xauthority file:

[iaroki@fedora ~]$ lxc config device add chrome X0 disk path=/tmp/.X11-unix/X0 source=/tmp/.X11-unix/X0
[iaroki@fedora ~]$ lxc config device add chrome Xauthority disk path=/home/iaroki/.Xauthority source=${XAUTHORITY}

Passthrough GPU device:

[iaroki@fedora ~]$ lxc config device add chrome GPU gpu
[iaroki@fedora ~]$ lxc config device set GPU uid 1000
[iaroki@fedora ~]$ lxc config device set GPU gid 1000

Check results with:

[iaroki@fedora ~]$ lxc exec chrome -- sudo --login --user iaroki
iaroki@chrome:~$ export DISPLAY=:0
iaroki@chrome:~$ echo "export DISPLAY=:0" >> ~/.profile
iaroki@chrome:~$ glxgears

Now we can install and run chromium browser inside:

[iaroki@fedora ~]$ lxc exec chrome -- sudo --login --user iaroki
iaroki@chrome:~$ sudo apt install chromium
iaroki@chrome:~$ chromium
Advertisements
Running GUI applications in LXD on Fedora 26

LXD installation on Fedora 26

LXD is not working with enabled SELinux so we need to disable it with comand:

[root@fedora ~]# setenforce permissive

Enable ganto repository to download neded packages:

[root@fedora ~]# dnf copr enable ganto/lxd

Now time to install LXD:

[root@fedora ~]# dnf install lxd lxd-client lxd-tools

In order to run lxc tools our user need to be in a lxd group, so add it:

[root@fedora ~]# usermod -aG lxd iaroki

Set sub{u,g}id’s range for containeraized root user:

[root@fedora ~]# echo "root:1000000:65536" >> /etc/subuid
[root@fedora ~]# echo "root:1000000:65536" >> /etc/subgid

Enable and start LXD daemon:

[root@fedora ~]# systemctl enable lxd.service
[root@fedora ~]# systemctl start lxd.service

Finally run LXD initialization:

[root@fedora ~]# lxd init

And now as a normal user (iaroki in my case) start container:

[iaroki@fedora ~]$ lxc launch images:debian/stretch mydebian
[iaroki@fedora ~]$ lxc exec mydebian bash
root@mydebian:~#

Enjoy LXD!

LXD installation on Fedora 26