A minimal systemd enabled centos9 Docker image for testing Ansible roles with Molecule.
NOTE: This image does NOT contain Ansible tooling, e.g. ansible-core
or yamllint
. Thus, the use case is as target
host for Ansible controllers or within the Molecule create
/converge
/test
cycle.
docker pull trfore/docker-centos9-systemd
This image is built on Docker Hub automatically any time the upstream OS image is rebuilt, and any time a commit is made
or merged to the main
branch. But if you need to build the image on your own locally, do the following:
- Install docker
- Clone the repo,
git clone https://github.com/trfore/docker-centos9-systemd.git
cd
into the directory- Run
docker build --tag trfore/docker-centos9-systemd .
-
Add the following code to your molecule scenario file, e.g.
molecule/default/molecule.yml
.platforms: - name: instance image: trfore/docker-centos9-systemd:latest tmpfs: - /run - /tmp volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw cgroupns_mode: host privileged: true pre_build_image: true
-
Install docker
-
Build an image locally (see above) or pull from Docker Hub:
docker pull trfore/docker-centos9-systemd:latest
-
Run a container from the image:
docker run -d -it --name centos9-systemd --privileged --cgroupns=host --tmpfs=/run --tmpfs=/tmp --volume=/sys/fs/cgroup:/sys/fs/cgroup:rw trfore/docker-centos9-systemd:latest
-
Use it, example:
docker exec -it centos9-systemd /bin/bash
-
Podman defaults to running containers in systemd mode,
--systemd=true
, and will mount the required tmpfs and cgroup filesystem. See Podman Docs: Commandsrun --systemd
for details.podman run -d -it --name centos9-systemd docker.io/trfore/docker-centos9-systemd:latest
Taylor Fore (https://github.com/trfore)
Inspired by Jeff Geerling's (@geerlingguy), CentOS 8, Debian 10/11, and Ubuntu 20/22 docker images for ansible, geerlingguy/docker-*-ansible.
- https://molecule.readthedocs.io/en/stable/index.html
- https://molecule.readthedocs.io/en/stable/examples.html#systemd-container
- https://developers.redhat.com/blog/2016/09/13/running-systemd-in-a-non-privileged-container
- github runner - ubuntu 20.04 preinstalled software
- github runner - ubuntu 22.04 preinstalled software