When wanting to use desktop applications via a container, it is helpful to be able to set up the container to have a desktop environment accessible via VNC.
I started this by using the Proxmox template for Ubuntu 22.04. At this time of writing, the 24.04 template is more than a bit ‘iffy’ and doesn’t work well. So we’ll go with 22.04 for it.
To give credit where credit is due, I found multiple sources for this information. References are below for what I found.
Install the template on a container. About 4GB RAM and a few processor cores is good.
Once ready, configure the system as you wish (e.g. add a user, set up VIM defaults) and run the following to make sure things are up to date:
apt-get update ; apt -y upgrade
Then to install the desktop software
Desktop software
To start with installing the desktop and VNC software you will need to do the following:
apt install xfce4 xfce4-goodies xorg dbus-x11 x11-xserver-utils
VNC for Multiple users
I am using tigerVNC and wanted it to be able to run on a per-user basis. I started by installing the software.
apt install tigervnc-standalone-server gdm3
For most uses, having the VNC service run all the time with a user is fine but I wanted to have things set up so that I would only be running the X desktop services when I actually log in to it. Then the container/VM can just sit there otherwise with relatively no processes running. To that end I made the following systemd unit files:
/etc/systemd/system/xvnc.socket
[Unit]
Description=XVNC Server on port 5900
[Socket]
ListenStream=5900
Accept=yes
[Install]
WantedBy=sockets.target
/etc/systemd/system/xvnc@.service (make sure to get the '@' symbol in there)
[Unit]
Description=Daemon for each XVNC connection
[Service]
ExecStart=-/usr/bin/Xvnc -inetd -query localhost -geometry 2000x1200 -depth 24 -once -SecurityTypes=None
User=nobody
StandardInput=socket
StandardError=syslog
Then run:
systemctl enable xvnc.socket
To set the default session to XFCE4 you will need to run:
update-alternatives --set x-session-manager /usr/bin/xfce4-session
However, that seems to sometimes not work so you might want to look at the file /var/lib/AccountsService/users/{user}
where {user}
is your username you made earlier. In that file is a setting for ‘session’
Reboot your container/VM at this time.
Using your favorite VNC software you should be able to VNC to your system and see the gdm greeter. You can then log in and X services will start. Note too that you can select the gear-wheel icon on the gdm greeter bottom-right and select what session type to use.
To note, I did have some awful trouble with more complicated desktop environments since they didn’t seem to like being installed within a containerized environment. It kept blocking/hanging on installing if any of the ‘-desktop’ packages were installed.
References
https://forum.proxmox.com/threads/how-to-create-a-template-for-lxc-ubuntu-desktop-with-sound.73695
https://serverfault.com/questions/1106319/set-up-tigervnc-on-ubuntu-20-02-with-systemd