I am a newbie to containers. I am trying to run a qt application from lxc container on RPI. I have compiled the code, but when i run it i get the error “cannot connect to X server :0.0”. I have successfully run the same code outside container, so there is no error with the application. But i have not set up the display to use by the container. Can somebody please guide me how to set up the display for lxc containers.
In order to run an X application in a container, you need to arrange for the output to appear on some X server.
If you are a Linux user, then you already run an X server on your system (for example, with Ubuntu).
In that case, you need to arrange to connect to this container over ssh, using the -X flag.
By doing so, the X application in the container will get forwarding through the SSH connection and appear on your Ubuntu desktop.
There are two common ways to make this direct SSH connection to the LXD container from your desktop to the RPi. One is by getting the container in the RPi to get a LAN IP address, then you can SSH directly from your host.
ssh -X firstname.lastname@example.org
The other way is to setup a proxy device on the RPi so that, let’s say, port 2222 on the RPi will proxy connections to port 22 at the container. You can do this by running (on the host at the RPi) the following,
lxc config device add mycontainer myport2222 proxy listen=tcp:0.0.0.0:2222 connect=tcp:127.0.0.1:22
Then, you can SSH from your desktop to the container with
ssh -X email@example.com
(assuming that the IP of the RPi is 192.168.1.100).
Thanks for the quick reply. I tried the first method you suggested. I was able to ssh into the container(ubuntu container) from the host. But when i tried to execute the binary i got the same error “cannot connect to X server :0.0”. Am i doing it correctly?
Also in the second method you are using the ‘lxc config device’ command but that is not present in the version i am using. I am using lxc version : 2.0.7 (not lxd). The commands are in the form ‘lxc-xxxx’, for example 'lxc-config '.