Video driver under lxc container?
Please, take a look at this script to create a LXC container that runs steam with sound and video acceleration:
http://bazaar.launchpad.net/~ubuntu-lxc/lxc/steam-lxc/view/head:/steam-lxc
The magic comes here:
Outside LXC:
# Add the bind mounts to the container's fstab
self.container.set_config_item("lxc.mount.entry",
"/tmp/.X11-unix tmp/.X11-unix "
"none bind,ro")
self.container.set_config_item("lxc.mount.entry",
"/dev/dri dev/dri none bind,ro")
self.container.set_config_item("lxc.mount.entry",
"%s/pulse.socket home/%s/.pulse_socket "
"none bind,ro" % (self.config_path,
self.user.pw_name))
We export X11 with a bind mount the /tmp/.X11-unix
directory to allow container to use host X11. Do the same with /dev/dri
directory and audio socket.
Inside LXC:
# Get pulseaudio to listen on the socket
with self.user_privileges():
subprocess.call(['pactl', 'load-module',
'module-native-protocol-unix',
'socket=%s' % self.pulse_socket,
'auth-cookie-enabled=0'])
# Start steam
self.run_command(
["steam"], {'DISPLAY': os.environ['DISPLAY'],
'PULSE_SERVER': "/home/%s/.pulse_socket" %
self.user.pw_name})
Uses pactl
to use a unix socket to communicate with host pulse audio server and later export the socket and DISPLAY
environment variable to allow steam to use local X11 server and socket to audio server.
Take a look at the script and enjoy it :)
With that environment variables inside LXC you could play (theoretically) almost all games.
Best regards!
Related videos on Youtube
lurscher
Updated on September 18, 2022Comments
-
lurscher over 1 year
Since LXC (Linux Containers) is a kernel level super-chroot, I've been wondering what sort of video driver the containers have:
My host is Ubuntu 12.04 64-bit machine with ATI gpu. Will the LXC container have access to the same driver? Or do they need to be installed on each container?
-
Admin over 11 yearsPlease share a bit more on what you're trying to accomplish. Are you trying to run GUI applications or even OpenGL-enabled applications in your LXC container?
-
-
gertvdijk over 11 yearsYour link is a page about the Libvirt LXC client/plugin, they call a 'driver'. I don't see any information regarding video drivers or alike.
-
lurscher over 11 yearsso, the question is: if i run
LIBGL_DEBUG=verbose glxinfo | grep rendering
inside the lxc container console, will i see "direct rendering: yes"? -
gertvdijk over 11 years@lurscher I can't tell what you will see on your hardware. Usually, people are not running anything directly related to hardware in containers. Either way, I think this article might give you some insight.
-
lurscher over 11 yearsi mean, i can see direct rendering: yes on the host, but that doesn't translate directly to the container, because the system installation (including the fglrx driver) will not be shared with the containers, right? That article seems to point that at least some direct rendering is possible using the open source driver, which is a good fallback plan for me, but if i could rely on the propietary fglrx ati driver it would be golden
-
lurscher almost 9 yearsinteresting. Have you tried to have at least 2 simultaneous containers using HW acceleration?
-
OscarGarcia almost 9 yearsNo, I'm currently using Docker (not plain LXC) to run Gazebo 5 containers, I didn't try to run two containers running accelerated applications at once. I'll try it this afternoon and I'll tell you if it works (I think that it'll work).
-
OscarGarcia almost 9 yearsSorry for the delay. Yes, it is possible to run multiple LXC containers and run simultaneously several accelerated applications. Take a look to this video that I recorded for you: youtu.be/RAUtZBaN1Oo
-
OscarGarcia almost 9 yearsHere is the github repository with the code used in the video: github.com/ojgarciab/docker3d
-
lurscher almost 9 yearsso,
create.sh
andcreate2.sh
create the two containers andstart.sh
andstart2.sh
start each separately. What doesmake.sh
do and in what order should it be run? -
OscarGarcia almost 9 years
make.sh
builds the template "ub1404-dev" from template "ubuntu:14.04", creating user redstar with its home directory, installs mesa-utils, ect. Thencreate[2].sh
create a template named "ub1404-dev[2]" from "ub1404-dev" template, bind mounting/dev/dri
and/tmp/.X11-unix
directories inside the container (and my own home directory). Before that we stop and destroy container if it was created and running previously. Then we could runstart[2].sh
to start running the container at background (but for now nothing executing on it). -
OscarGarcia almost 9 yearsAt the very end we run commands inside the containers: we execute a bash shell. -- We could connect with
ssh -X [email protected]
(installing previously openssh-server) and running X applications as we do normally with remote servers, but without hardware acceleration. -
OscarGarcia almost 9 yearsSorry: "Then create[2].sh create a LXC CONTAINER named "ub1404-dev" and "ub1404-dev2" from same "ub1404-dev" template". So we use the common template to create two different (and isolated) LXC containers.