Recently I noticed that previous configurations to spin up docker instances with systemd enabled within Molecule-powered tests didn’t work anymore. Unfortunately, I didn’t have the slightest clue why and how to fix this. Usually, a bit of Google search solves most of the problems, but either I used the wrong search strings or there was simply little documentation about this. Long story short, if nothing helps, there is still Jeff Geerling and his blog.
He stumbled upon the same issue and explained in his article Docker and systemd, getting rid of dreaded ‘Failed to connect to bus’ error what it’s about and how to fix. Essentially, the problem resulted when cgroups switched from version 1 to version 2. With cgroups v2 you need to add an additional switch “–cgroupns=host” to the Docker command to solve this issue. With Molecule, the full configuration looks like this one:
platforms: - name: AlmaLinux-9 image: docker.io/almalinux/9-init command: "" volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw - /var/lib/containerd cgroupns_mode: host privileged: true pre_build_image: true
In this configuration I use AlmaLinux. They have pre-build images ending with init that indicates that they use systemd after start up. The command is set to nothing to use the command as defined in the Docker file.