Running Gui apps in LXD

I’ve been trying to run gui applications inside an lxd container for ros but have been facing issues. Guidance will be greatly appriciated.

config:
  environment.DISPLAY: :1
  raw.idmap: both 1000 1000
  user.user-data: |
    #cloud-config
    runcmd:
      - 'sed -i "s/; enable-shm = yes/enable-shm = no/g" /etc/pulse/client.conf'
      - 'echo export PULSE_SERVER=unix:/tmp/.pulse-native | tee --append /home/ubuntu/.profile'
    packages:
      - x11-apps
      - mesa-utils
      - pulseaudio
description: GUI LXD profile
devices:
  PASocket:
    path: /tmp/.pulse-native
    source: /run/user/1000/pulse/native
    type: disk
  X0:
    path: /tmp/.X11-unix/X0
    source: /tmp/.X11-unix/X0
    type: disk
  Xauth:
    path: /home/user/.Xauthority
    source: /run/user/1000/gdm/Xauthority
    type: disk
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: ros
used_by:
- /1.0/instances/noetic

running tail -6 /var/log/cloud-init.log

ubuntu@noetic:~$ tail -6 /var/log/cloud-init.log
2020-11-20 03:14:30,438 - atomic_helper.py[DEBUG]: Atomically writing to file /var/lib/cloud/data/result.json (via temporary file /var/lib/cloud/data/tmpnll0apqx) - w: [644] 119 bytes/chars
2020-11-20 03:14:30,439 - util.py[DEBUG]: Creating symbolic link from '/run/cloud-init/result.json' => '../../var/lib/cloud/data/result.json'
2020-11-20 03:14:30,439 - util.py[DEBUG]: Reading from /proc/uptime (quiet=False)
2020-11-20 03:14:30,439 - util.py[DEBUG]: Read 11 bytes from /proc/uptime
2020-11-20 03:14:30,439 - util.py[DEBUG]: cloud-init mode 'modules' took 24.821 seconds (24.82)
2020-11-20 03:14:30,439 - handlers.py[DEBUG]: finish: modules-final: SUCCESS: running modules for final

running xclock

ubuntu@noetic:~$ xclock 
Error: Can't open display: :1

On the host pc , running `$DISPLAY`
[ Thu Nov 19, 22:28:19 wolf1990@ad: ~/codebase/ros ]
└─ $ $DISPLAY
:1: command not found

Use proxy type for X0 device, the profile I am using:

lxc profile create x11app <<EOF
config:
  environment.DISPLAY: :1
description: Default LXD profile
devices:
  X1:
    bind: container
    connect: unix:@/tmp/.X11-unix/X1
    listen: unix:@/tmp/.X11-unix/X1
    type: proxy
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
EOF

Thanks for the tip! I modified my profile as follows and everything is working fine. Spent this week learning in’s and out’s of LXD and think i have a firm hand on it

config:
  environment.DISPLAY: :0
  environment.PULSE_SERVER: unix:/home/ubuntu/pulse-native
  nvidia.driver.capabilities: all
  nvidia.runtime: "true"
  raw.idmap: both 1000 1000
  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: LXC profile for ROS
devices:
  PASocket1:
    bind: container
    connect: unix:/run/user/1000/pulse/native
    gid: "1000"
    listen: unix:/home/ubuntu/pulse-native
    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
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  mygpu:
    type: gpu
  root:
    path: /
    pool: default
    type: disk
name: ros
used_by:
- /1.0/instances/c-ros-noetic