1

I want to have a setup where I have LXC OS containers that start full-screen on particular displays. As an intermediate step, I am trying to get X apps from the container to display via host X.

I have been using this as a guide: https://blog.simos.info/running-x11-software-in-lxd-containers/

My procedure is like this:

Create a profile for running X11 containers.

cat<<EOF>x11.profile
config:
  environment.DISPLAY: :0
  environment.PULSE_SERVER: unix:/home/ubuntu/pulse-native
  nvidia.driver.capabilities: all
  nvidia.runtime: "true"
  user.user-data: |
    #cloud-config
    runcmd:
      - 'sed -i "s/; enable-shm = yes/enable-shm = no/g" /etc/pulse/client.conf'
    packages:
      - x11-apps
      - mesa-utils
      - pulseaudio
description: GUI LXD profile
devices:
  PASocket1:
    bind: container
    connect: unix:/run/user/1000/pulse/native
    listen: unix:/home/ubuntu/pulse-native
    security.gid: "1000"
    security.uid: "1000"
    uid: "1000"
    gid: "1000"
    mode: "0777"
    type: proxy
  X0:
    bind: container
    connect: unix:@/tmp/.X11-unix/X0
    listen: unix:@/tmp/.X11-unix/X0
    security.gid: "1000"
    security.uid: "1000"
    type: proxy
  mygpu:
    type: gpu
name: x11
used_by: []
EOF

lxc profile create x11 cat x11.profile | lxc profile edit x11

I can then create the container (although X needs to be started, which I did not at first realize was necessary)

$ lxc launch ubuntu:18.04 --profile default --profile x11 mycontainer
Creating mycontainer
Starting mycontainer
Error: Failed to run: /snap/lxd/current/bin/lxd forkstart mycontainer /var/snap/lxd/common/lxd/containers /var/snap/lxd/common/lxd/logs/mycontainer/lxc.conf: 
Try `lxc info --show-log local:mycontainer` for more info

$ sudo startx & [1] 12745 $ X.Org X Server 1.20.11 X Protocol Version 11, Revision 0 Build Operating System: linux Ubuntu Current Operating System: Linux virtland 5.11.0-40-generic #44~20.04.2-Ubuntu SMP Tue Oct 26 18:07:44 UTC 2021 x86_64 Kernel command line: BOOT_IMAGE=/BOOT/ubuntu_2aec3h@/vmlinuz-5.11.0-40-generic root=ZFS=rpool/ROOT/ubuntu_2aec3h ro init_on_alloc=0 amd_iommu=on vfio_pci.ids=10de:1b81,10de:10f0,1002:67df,1002:aaf0,1b21:1242 crashkernel=512M-:192M Build Date: 06 July 2021 10:17:51AM xorg-server 2:1.20.11-1ubuntu1~20.04.2 (For technical support please see http://www.ubuntu.com/support) Current version of pixman: 0.38.4 Before reporting problems, check http://wiki.x.org to make sure that you have the latest version. Markers: (--) probed, (**) from config file, (==) default setting, (++) from command line, (!!) notice, (II) informational, (WW) warning, (EE) error, (NI) not implemented, (??) unknown. (==) Log file: "/var/log/Xorg.0.log", Time: Wed Nov 17 18:29:01 2021 (==) Using config file: "/etc/X11/xorg.conf" (==) Using system config directory "/usr/share/X11/xorg.conf.d" $ lxc launch ubuntu:18.04 --profile default --profile x11 mycontainer Creating mycontainer Starting mycontainer

When I run xeyes from within the container, I cannot connect to the display.

I had this working with a previous install (it would make xeyes appear on the host desktop, but without the desktop it would bring up a bare xterm window instead of xeyes), but for some reason now it is not working at all and I cannot seem to figure out what I have done differently.

~$ lxc exec mycontainer -- sudo --user ubuntu --login
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@mycontainer:~$ xeyes No protocol specified Error: Can't open display: :0

So, for starters, I'd like to be able to make xeyes appear on the host desktop again.

Eventually I would like to be able to run it with bare X and no window manager, and eventually run a full DE using that procedure.

System info: OS: Ubuntu Server 20.04 LXD verison: 4.20 LXC version: 4.20

1 Answers1

1

I finally found an answer here: Why can't I run GUI apps from 'root': "No protocol specified"?

I just ran:

sudo startx & #I'm pretty sure it isn't ideal to startx as root
sudo -i
xhost si:localuser:MYUSERID
exit

and then when I went into my container and ran xeyes, it appeared on the display without even a window manager. I am not sure what other things I did that also might have made a difference. On this round I installed my drivers like:

sudo apt install --no-install-recommends nvidia-driver-470-server nvidia-utils-470-server nvidia-prime xfonts-base libc-dev libc6-dev fakeroot build-essential gnupg2 dbus-user-session mesa-vulkan-drivers

I doubt all that is necessary, but I don't have the time or patience to empirically separate fact from superstition. If it works that's good enough for me.