how to run open source games in docker container

  • build docker images for each game
docker build -t sang0627/systemd -f Dockerfile.systemd .
docker build -t sang0627/xspice -f Dockerfile.xspice .
docker build -t sang0627/opentyrian -f Dockerfile.opentyrian .
docker build -t sang0627/supertux -f Dockerfile.supertux .
docker build -t sang0627/supertuxkart -f Dockerfile.supertuxkart .

cat Dockerfile.systemd

FROM ubuntu:18.04
MAINTAINER "Moon-Sang Lee" <sang0627@gmail.com>
ENV container docker
RUN find /etc/systemd/system \
    /lib/systemd/system \
    -path '*.wants/*' \
    -not -name '*journald*' \
    -not -name '*systemd-tmpfiles*' \
    -not -name '*systemd-user-sessions*' \
    -exec rm \{} \;
RUN apt update && apt install -y dbus systemd apt-utils && \
    apt clean && rm -rf /var/lib/apt/lists/*
RUN systemctl set-default multi-user.target
RUN systemctl mask dev-hugepages.mount sys-fs-fuse-connections.mount
#RUN mkdir /host
#COPY setup.sh /sbin/
VOLUME ["/sys/fs/cgroup"]
STOPSIGNAL SIGRTMIN+3
CMD ["/bin/bash", "-c", "exec /sbin/init --log-target=journal 3>&1"]

cat Dockerfile.xspice

FROM sang0627/systemd
MAINTAINER "Moon-Sang Lee" <sang0627@gmail.com>
ENV container docker
RUN apt update && apt install -y xserver-xspice xinput spice-vdagent dbus-x11
COPY xspice.service /lib/systemd/system/
COPY spiceqxl.xorg.conf /etc/X11/
RUN echo "SPICE_VDAGENTD_EXTRA_ARGS=-X" >> /etc/default/spice-vdagentd
RUN systemctl enable xspice
EXPOSE 5909
STOPSIGNAL SIGRTMIN+3
CMD ["/bin/bash", "-c", "exec /sbin/init --log-target=journal 3>&1"]

cat Dockerfile.opentyrian

FROM sang0627/xspice
MAINTAINER "Moon-Sang Lee" <sang0627@gmail.com>
ENV container docker
RUN apt update && apt install -y libsdl2-net-2.0-0 opentyrian git python3-setuptools && \
    cd /tmp && /usr/games/game-data-packager -n tyrian && dpkg -i tyrian-data*.deb
COPY opentyrian.service /lib/systemd/system/
RUN systemctl enable opentyrian
RUN cd /tmp && git clone https://github.com/novnc/websockify.git && \
    cd websockify && python3 setup.py install
COPY websockify.service /lib/systemd/system/
RUN systemctl enable websockify
STOPSIGNAL SIGRTMIN+3
CMD ["/bin/bash", "-c", "exec /sbin/init --log-target=journal 3>&1"]

cat Dockerfile.supertux

FROM sang0627/xspice
MAINTAINER "Moon-Sang Lee" <sang0627@gmail.com>
ENV container docker
RUN apt update && apt install -y libsdl2-net-2.0-0 supertux
COPY supertux.service /lib/systemd/system/
RUN systemctl enable supertux
STOPSIGNAL SIGRTMIN+3
CMD ["/bin/bash", "-c", "exec /sbin/init --log-target=journal 3>&1"]

cat Dockerfile.supertuxkart

FROM sang0627/xspice
MAINTAINER "Moon-Sang Lee" <sang0627@gmail.com>
ENV container docker
RUN apt update && apt install -y libsdl2-net-2.0-0 supertuxkart
COPY supertuxkart.service /lib/systemd/system/
RUN systemctl enable supertuxkart
STOPSIGNAL SIGRTMIN+3
CMD ["/bin/bash", "-c", "exec /sbin/init --log-target=journal 3>&1"]

  • test your game container one by one
docker run -d --name opentyrian -p 5901:5901 -p 5909:5909 --security-opt seccomp=unconfined --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro -t sang0627/opentyrian
docker stop opentyrian

docker run -d --name supertux -p 5909:5909 --security-opt seccomp=unconfined --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro -t sang0627/supertux
docker stop supertux

docker run -d --name supertuxkart -p 5909:5909 --security-opt seccomp=unconfined --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro -t sang0627/supertuxkart
docker stop supertuxkart

docker rm opentyrian
docker rm supertux
docker rm supertuxkart

websockify is only used in opentyrian just for test purpose


reference
https://hub.docker.com/r/solita/ubuntu-systemd
https://developers.redhat.com/blog/2014/05/05/running-systemd-within-docker-container/
https://developers.redhat.com/blog/2016/09/13/running-systemd-in-a-non-privileged-container/
https://developers.redhat.com/blog/2019/04/24/how-to-run-systemd-in-a-container/
https://www.linode.com/docs/quick-answers/linux/start-service-at-boot/
https://lwn.net/Articles/676831/
http://www.xonotic.org/

Leave a Reply

Your email address will not be published.