Running Prusa Slicer From A Rootless Podman Container
A while back Jessie Frazelle wrote a neat blog post on running desktop applications using Docker containers. It ends up that it isn’t too hard to run X clients in containers using podman or Docker .
Now that I have Alpine Linux running on my laptop I need to get rootless podman setup so I can run applications that aren’t included in the Alpine distribution. Podman is a Docker compatible container engine that doesn’t require a daemon, and can run as a user without any need for root access. That also means that there is a good chance this will all work on other distributions, not just on Alpine.
Podman setup on Alpine is easy. It amounts to installing the package, making sure the cgroups service is started, and most importantly adding subuids/gids for your user account. These are used for mapping the container uid/gid when running as a user. See the Alpine Wiki for the current instructions. Other distributions may have podman already setup, or have similarly simple instructions available.
Once you can successfully run podman run --rm hello-world
you are ready to
setup a container for prusa-slicer.
The Containerfile looks like this:
# Run Prusa Slicer in a container
#
# Based on Jessie Frazelle's post:
# https://blog.jessfraz.com/post/docker-containers-on-the-desktop/
FROM debian:latest
LABEL maintainer "Brian C. Lane <bcl@brianlane.com>"
RUN apt-get update && apt-get install -y \
prusa-slicer \
locales \
&& rm -rf /var/lib/apt/lists/*
# Update the locale
RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen en_US.utf8 \
&& /usr/sbin/update-locale LANG=en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV HOME /home/user
ENV USER user
RUN groupadd -g 1000 user \
&& useradd -u 1000 -g 1000 --create-home --home-dir $HOME user \
&& chown -R user:user $HOME
RUN passwd -d root
WORKDIR $HOME
USER user
I used debian:latest (currently set to bullseye), installed the needed apps,
setup the locale so that prusa-slicer wouldn’t crash. Setup a user named
user
, who has the same uid as the user on the host system and make a home
directory for them. I also delete the root password in the container to make it
easier to debug problems that may arise. One important thing is to set the
USER
environmental variable. Without that prusa-slicer crashes with a very
obscure error message. You may need to change the 1000
to the uid and gid of
your user.
Now you can build the container with podman build -t prusa-slicer -f Containerfile
.
X11 Permission
In order for the application to run it needs permission to talk to the X server on the host.
This is accomplished by running xhost, and by mounting the X11 socket in the container. If
your socket file is somewhere other than ~/.X11-unix
you will need change it to the correct
path. You also need to tell the prusa-slicer app where the display is, which is done by
setting the DISPLAY
environmental variable using podman’s -e
option.
Mountpoints
I use the ~/Downloads/
directory to share the .stl
and .gcode
files with
the container, and ~/PrusaSlicer
to store the configuration between runs.
Create these 2 directories in your home directory if they don’t already exist
on your system.
Running the container
The run script looks like this:
#!/bin/sh
CMD=""
if [ -z "$1" ]; then
CMD=prusa-slicer
else
CMD="$*"
fi
xhost +si:localuser:"$USER"
podman run --rm -it --userns=keep-id -v "$HOME/Downloads:/home/user/Downloads" \
-v "$PWD/PrusaSlicer:/home/user/.config/PrusaSlicer" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e "DISPLAY=unix$DISPLAY" \
prusa-slicer "$CMD"
xhost -si:localuser:"$USER"
This uses xhost
to give the current user permission to connect to the server,
launches the container with the ~/Downloads/
and ~/PrusaSlicer
directories
mounted, along with the X socket. If you just run it, it will start the prusa-slicer
app. If you need to debug things run it with /usr/bin/bash
and it will run a
shell inside the container.
With prusa-slicer running select the .stl
files from ~/Downloads
inside the
container, and export the .gcode
back to the same place. They will appear in
the ~/Downloads/
directory on the host filesystem for transfer to your 3d
printer.
You can find the files here in a git repo .