I'm trying to set up my Linux machine to run multiple guest OSes, one of those being a Windows VM, and another a Linux container. The goal here is to prevent me from messing up the host system, while being free to operate the base operating system and play with the host hardware. Eventually, on top of running my desktop in the container, I hope to run graphics-accelerated simulations, etc. Since Docker has such nice git-like versioning of containers built-in, it seemed like a good idea to use it. Perhaps libvirt would do just as good with LXC, but docker's privileged mode makes it easier to not have to configure devices to the container.

I've done a little research and come up with a few answers already, but I'm having trouble putting it all together.

Background in LXC

Running X from LXC helped me to see how I can configure a container with (i.e.):

lxc.cgroup.devices.allow = c 226:0 rwm

and using

mknod -m 666 dri/card0 c 226 0

inside the container to connect to the host device.


From cuda - Using GPU from a docker container, I saw that I can get the same setup to work in Docker with the LXC backend.

It appeared to me that if a docker container is run in privileged mode, then it can access the GPU normally without this extra configuration. So, I fired up a base system, installed graphics drivers, xorg-server, xorg-xinit, and a window manager to test it out.

First try

# startx
Cannot run from a console (or some message like that)

Okay, I thought I was on tty2.

# tty

That's not what I expected.

# chvt 2
# tty

Well, it appears as if that worked. Let's try # startx again. It started the window manager, with the cursor in the center. No mouse response. No keyboard response. Let's try to change the tty with Ctrl-Alt+F3. No response. Well, it looks like I'll have to reboot cold.

Second try

# tty
# chvt 2
# tty

What? I can't change it now?


After trying another time, I got it to change tty, and startx froze the computer again.

What now?

So, I'm now at an impass. I really want to be able to use a container - Docker preferred, LXC with libvirt is also acceptable - to run as my daily operating system while keeping a lean host OS.

Is it best to use Docker with privileged mode here, or to use the explicit LXC backend and try the options listed above?

I am already planning on using libvirt (possibly under vagrant-libvirt) to manage my Windows vm, so would it be about the same for me to use libvirt or vagrant-LXC in this case?

Edit: reading LXC vs. Docker, I get the feeling that since Docker and Docker containers are meant for single-application environments, perhaps it would be best to use LXC instead of Docker to run as my daily operating system. Thoughts?

Edit: I've discovered that, like docker, there is a lxc-device command which allows me to bypass the cgroups and mknod steps. Whereas before I was able to get x to start and freeze my system, it just errors out now. Perhaps I can figure this out eventually, since no one seems to be out there.

Update: I have the mouse working. On the guest, I installed xf86-input-mouse and xf86-input-keyboard. On the host, I ran the following:

# lxc-device -n g1 add /dev/input/mice
# lxc-device -n g1 add /dev/dri/card0
# lxc-device -n g1 add /dev/dri/controlD64
# lxc-device -n g1 add /dev/dri/renderD128
# lxc-device -n g1 add /dev/fb0
# lxc-device -n g1 add /dev/tty2


  • I'm pretty convinced that LXC is what I need to use, and not Docker. Unfortunately, it's a pretty hard time to find up-to-date documentation on binding a specific tty to a container so that I can run X. Both my host and guest use systemd, whereas all the documentation around is /etc/inittab related. Does anyone know how to work with LXC containers correctly to get them to "own" a tty on the host?
    – Paul
    Mar 20, 2015 at 19:36
  • When I gave LXC its own tty, and assign video cards to it, I tried startx with exec twm, but the whole thing was frozen from my perspective. No response to keyboard or mouse.
    – Paul
    Mar 23, 2015 at 13:23
  • unix.stackexchange.com/questions/18003/linux-lxc-deploying-images-with-tiniest-possible-x11 seems to have a relevant answer. I think that I need to forward the /dev/input chain. I'll try that.
    – Paul
    Mar 23, 2015 at 15:55
  • It sounds like unix.stackexchange.com/questions/18003/… had the answer, according to irclog.perlgeek.de/crimsonfu/2015-03-23#i_10327389 Mar 24, 2015 at 10:08
  • Well, I thought that I had the keyboard sorted out. But now it doesn't work again.
    – Paul
    Mar 24, 2015 at 18:04

1 Answer 1


This question had the answer that I needed. Of course, I used lxc-device instead of cgroup definitions in the config file. However, in my case, I have only gotten the keyboard to work in X if I start it on a different tty.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.