How do I target a container to a monitor (or X screen)

After much difficulty, I set up two X screens such that I can target xeyes to either screen0 or screen1 like this:

:~$ DISPLAY=:0.0 xeyes # appears on left screen

~$ DISPLAY=:0.1 xeyes # appears on right screen

However, when trying to do the same thing with my LXC container, targeting the display does not work, and with either command the xeyes from my container opens on screen0.

~$ DISPLAY=:0.0 lxc exec mycontainer xeyes # appears on left screen
~$ DISPLAY=:0.1 lxc exec mycontainer xeyes #appears on left screen

Interestingly, if I run xeyes from within the container, I can target either screen.

ubuntu@mycontainer2:~$ DISPLAY=:0.0 xeyes # appears on left screen
ubuntu@mycontainer2:~$ DISPLAY=:0.1 xeyes # appears on right screen

So, is there a way that I can target a container to a screen at the time I open the container?

lxc exec doesn’t carry environment into the container.

Use lxc exec mycontainer --env DISPLAY=:0.1 xeyes and that should work better.

1 Like

Yes, that did it!