Install Steam in a docker container using distrobox (solved)
I like to keep my main system as bare bones as possible (it is not though).
Projects that come with a plethora of libraries, I try to containerize. My
script wraps commands such as
jekyll into commands that then start and
execute a container, but it still was some work to get the Dockerfiles up.
But today I tried something different and I think my old ways may be obsolete now. The name of the possible gamechanger is distrobox.
Install stable distrobox (18.104.22.168)
I used the lazy install method, after all distrobox is just a bunch of shell scripts:
curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install | sudo sh
Create a container/distrobox
See the end of this article if you have a NVidia card.
Now let’s create an ubuntu container named “steam” to host the steam executable:
distrobox create -n steam \ --image ubuntu:latest \ -p \ --yes \ --home ~/.distrobox/steam distrobox enter steam
-n steam: name of the container,
--image ubuntu:latest: docker image to base the container on,
--yes: pull, without asking, –home ~/.distrobox/steam : use a custom home directory for less trouble
I am gonna call a container managed by
distrobox a “distrobox” from here on.
Install Steam in distrobox
Now in the distrobox:
curl -L -O https://repo.steampowered.com/steam/archive/stable/steam_latest.deb sudo dpkg --add-architecture i386 sudo apt update sudo apt -y dist-upgrade sudo apt -y install pciutils udev libcanberra-gtk-module # install and fix missing dependencies afterwards sudo dpkg -i steam_latest.deb sudo apt -y -f install sudo apt install libc6-i386 # libgl1:i386 libdrm2:i386 libegl1:i386 libgbm1:i386 # depends on ubuntu version seemingly sudo apt install steam-libs-amd64 steam-libs-i386 sudo ldconfig
Export steam as a local command
The command will be available in a
bin folder of my choosing that
is reachable from the distrobox. So still in the distrobox:
distrobox-export --bin `which steam` --export-path /home/nat/bin
Once it’s out there on the host, I can move the command to any place I like.
Now back on the host:
This will also work, if the distrobox is not running anymore. The output should look something like this:
Container steam is not running. Starting container steam run this command to follow along: docker logs -f steam Starting container... [ OK ] Installing basic packages... [ OK ] Setting up read-only mounts... [ OK ] Setting up read-write mounts... [ OK ] Setting up host's sockets integration... [ OK ] Integrating host's themes, icons, fonts... [ OK ] Setting up package manager exceptions... [ OK ] Setting up dpkg exceptions... [ OK ] Setting up apt hooks... [ OK ] Setting up sudo... [ OK ] Setting up groups... [ OK ] Setting up users... [ OK ] Executing init hooks... [ OK ] Container Setup Complete! Unable to determine whether the expected Nvidia drivers are available. The Steam client may have limited functionality. steam.sh: Running Steam on ubuntu 22.04 64-bit steam.sh: STEAM_RUNTIME is enabled automatically setup.sh: Steam runtime environment up-to-date! steam.sh: Steam client's requirements are satisfied WARNING: setlocale('en_US.UTF-8') failed, using locale: 'C'. International characters may not work. [2023-05-13 00:57:28] Startup - updater built Apr 28 2023 18:32:42 [2023-05-13 00:57:28] Startup - Steam Client launched with: '/home/nat/.distrobox/steam/.local/share/Steam/ubuntu12_32/steam' ...
Patience is a virtue here, as steam will take its time…
Then I installed one of my Linux compatible games, a small puzzler called The Tiny Bang Story. To my surprise it worked. Graphics worked without glitching, Sound worked. It was playable.
Though everything seems to work, I see a lot of errors like these, which presumably slow down the proceedings:
_IceTransSocketUNIXConnect: Cannot connect to non-local host myhost Could not connect to X session manager: Could not open network socket _IceTransSocketUNIXConnect: Cannot connect to non-local host myhost _IceTransSocketUNIXConnect: Cannot connect to non-local host myhost Could not connect to X session manager: Could not open network socket
I have the Portmaster firewall running. If I turn it off, the process is quite snappy. But the X11 warnings remain.
And the fix!
/etc/X11/xinit/xserverrc so tcp connections are accepted. (I have a
firewall, so I don’t mind):
#!/bin/sh exec /usr/bin/X -listen tcp "$@"
Now change the
steam command, that was exported in a previous step, so
SESSION_MANAGER environment variable is no longer exported:
#!/bin/sh # distrobox_binary # name: steam if [ ! -f /run/.containerenv ] && [ ! -f /.dockerenv ] then unset SESSION_MANAGER exec /usr/local/bin/distrobox-enter -n steam -- /usr/bin/steam "$@" else exec /usr/bin/steam "$@" fi
Now everything works smoothly.
This also fixes my Portmaster firewall interference problem. It doesn’t matter anymore, if the firewall is up or not!
A distrobox with explicit nvidia support
Install unstable distrobox
For this I needed a more cutting-edge version of “distrobox”:
curl -s https://raw.githubusercontent.com/89luca89/distrobox/main/install \ | sudo sh -s -- --next --prefix /usr/local
Create a container/distrobox
--privileged flag is admittedly just some voodoo from earlier attempts,
that may or may not be needed.
distrobox create -n steam-nvidia \ --image ubuntu:latest \ --nvidia \ -p \ --additional-flags "--privileged" \ --yes \ --home ~/.distrobox/steam distrobox enter steam-nvidia
Install Steam in distrobox
The next part is pretty much unchanged, but the command order is maybe a bit more sensible:
curl -L -O https://repo.steampowered.com/steam/archive/stable/steam_latest.deb sudo dpkg --add-architecture i386 sudo apt update sudo apt -y dist-upgrade sudo apt -y install pciutils udev libcanberra-gtk-module sudo apt -y install libc6-i386 # not needed with nvidia image nvidia/opengl:1.2-glvnd-runtime-ubuntu22.04 sudo apt -y libgl1:i386 libdrm2:i386 libegl1:i386 libgbm1:i386 # install and fix missing dependencies afterwards sudo dpkg -i steam_latest.deb sudo apt -y -f install sudo ldconfig
Everything else is, as explained before.
Then I downloaded and executed Quake 2 RTX and in the console, it recognized my NVidia card. So I would call this a success.
For some reason I always get a window popping up saying, that some packages are out of date. I don’t know how to fix this yet.