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!
My approach assumes that your server has a single NIC, and you need to share that NIC between the host and the LXC guests. This involves using a bridge. The bridge owns and manages eth0
. The host now configures its own networking on br0
instead of eth0
. The LXC guests are configured to connect to the bridge.
On the host, sudo apt-get install bridge-utils
.
On the host, replace eth0
with a bridge:
This is dangerous. Get this wrong and you could be locked out of your server. Be sure to have a local login enabled and that local console access works, so that you can revert this change if you have any problems.
In /etc/network/interfaces
:
- Replace
auto eth0
with auto br0
.
Replace:
iface eth0 inet dhcp
with:
iface br0 inet dhcp
bridge_ports eth0
If you had a static network configuration, then you'd replace:
iface eth0 inet static
address ...
netmask ...
gateway ...
etc.
with:
iface br0 inet static
bridge_ports eth0
address ...
netmask ...
gateway ...
etc.
You're just changing eth0
for br0
and adding the bridge_ports eth0
line.
Reboot the host. If you were doing this locally, then running sudo ifdown eth0
before you started, and sudo ifup br0
afterwards would also do. Note that the bridge can take a little time to come up, so give it five minutes after reboot before you assume that all is lost.
To move a given named LXC container over to a public IP:
- Stop the container.
- On the host, edit
/var/lib/lxc/container_name/config
and change lxc.network.link
to br0
.
- On the host, edit
/var/lib/lxc/container_name/rootfs/etc/network/interfaces
and configure your public IP as you would normally (DHCP or a static configuration as needed). Note that the interface is still called eth0
from the point of view of the container.
- Restart the container.
To change the default for new LXC containers, edit /etc/lxc/default.conf
on the host and change lxc.network.link
to br0
.
If you don't need the LXC-provided NAT bridge at all (ie. all your containers will use the new bridge instead), then on the host edit /etc/default/lxc
and change USE_LXC_BRIDGE
to "false"
, and then on the host run sudo service lxc restart
.
Best Answer
Your lxc guest will need a desktop but whether or not a full ubuntu-desktop or not depends on your use. Then you might wanta means to access a desktop in the container (VNC, xfreerdp/xrdp, x2go). In my lxc containers I install x2go server then use an x2go client (mac, pc, linux) to log into the lxc desktop. x2go clients support unity, gnome others so you can choose.
Also, you may need/want to modify ssh default port etc for the container (/etc/ssh/sshd_config) to something other than default but that may mean you may need to make a change on your router firewall also.