I believe @nicolamori managed to solve this see this post on stackoverflow, however my attempt to duplicate it initially resulted in a Docker container which, when run on a non-privileged runner, simply returned ERROR: Job failed: exit code 255
, however when run on a privileged runner it works perfectly on Debian Bookworm and Ubuntu Jammy however with Debian Bullseye the CI job doesn’t terminate until the GitLab CI timeout is reached — however this might be a molecule issue?
The only part of this potential solution I’ve written myself is the last section of the Dockerfile
:
COPY entrypoint.sh /entrypoint.sh
COPY bash.service /etc/systemd/system/bash.service
RUN chown root:root /entrypoint.sh \
&& chmod 755 /entrypoint.sh \
&& chown root:root /etc/systemd/system/bash.service \
&& chmod 644 /etc/systemd/system/bash.service \
&& systemctl enable bash.service
ENTRYPOINT ["/entrypoint.sh"]
Everything else has been copied from the stackoverflow comment linked above.
The only additional Debian package I have installed in the container, for this (I’m doing other things like installing Ansible) is systemd
.
Note that for Debian Bullseye systemd
is at /lib/systemd/systemd
rather than /usr/lib/systemd/systemd
where it is found for Debian Bookworm and Ubuntu Jammy.
One potential improvement that the entrypoint.sh
script could do with is a check if the container is running in privileged mode with a error message being returned if it is not, see for example the suggestion here however this might not be possible as the check might interfere with the PID assignment?