# How to setup docker container to test systemd when using molecule

**URL:** <https://forum.ansible.com/t/how-to-setup-docker-container-to-test-systemd-when-using-molecule/45491>\
**Category:** Get Help\
**Created:** [March 5, 2026, 6:49pm UTC](https://forum.ansible.com/t/how-to-setup-docker-container-to-test-systemd-when-using-molecule/45491 "2026-03-05T18:49:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FinalDes](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/finaldes/32/8759_2.png) [@FinalDes](https://forum.ansible.com/u/FinalDes)\
**Post date:** [March 5, 2026, 6:49pm UTC](https://forum.ansible.com/t/how-to-setup-docker-container-to-test-systemd-when-using-molecule/45491/1 "2026-03-05T18:49:34Z")

</div>

That docker file have  
[DockerFile](https://github.com/FinalDes/ansible-docker-image/blob/main/Dockerfile)

# /bin/systemctl

System has not been booted with systemd as init system (PID 1). Can’t operate.

```auto
  - name: Create a container
      community.docker.docker_container:
        name: "{{ item.name }}"
        image: "{{ item.image }}"
        state: started
        # command: sleep 1d
        command: /lib/systemd/systemd --system --log-level=info --log-target=console
        cgroupns_mode: private
        security_opts:
          - seccomp=unconfined
        log_driver: json-file
        volumes:
          - "/sys/fs/cgroup:/sys/fs/cgroup:rw"
          - "/tmp:/tmp"
          # - "/run:/run"
        privileged: true
        tmpfs:
          - /run
          - /run/lock
        env:
          container: docker
      register: result
      loop: "{{ molecule_yml.platforms }}"

```

do have something miss when execute the docker image

---

<div class="post-metadata">

**Author:** ![kks](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kks/32/10352_2.png) [@kks](https://forum.ansible.com/u/kks)\
**Post date:** [March 5, 2026, 8:27pm UTC](https://forum.ansible.com/t/how-to-setup-docker-container-to-test-systemd-when-using-molecule/45491/2 "2026-03-05T20:27:22Z")

</div>

> [@FinalDes](#):
>
> System has not been booted with systemd as init system (PID 1). Can’t operate.

Majority of containers do not contain systemd inside. There is a long story about that. Containers that do contain systemd commonly called init containers.

> **[Red Hat Universal Base Image 10 Init - Red Hat Ecosystem Catalog](https://catalog.redhat.com/en/software/containers/ubi10-init/66f2aabb701371ba5f56497a?image=686bd755edf0de590015a72d&container-tabs=overview)**
>
> Red Hat Universal Base Image 10 Init

Just an example

“  
The Universal Base Image Init is designed to run an init system as PID 1 for running multi-services inside a container. “

---

<div class="post-metadata">

**Author:** ![bvitnik](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bvitnik/32/4132_2.png) [@bvitnik](https://forum.ansible.com/u/bvitnik)\
**Post date:** [March 5, 2026, 9:59pm UTC](https://forum.ansible.com/t/how-to-setup-docker-container-to-test-systemd-when-using-molecule/45491/3 "2026-03-05T21:59:06Z")

</div>

You have to use Docker images that have systemd. I’m using these:

> **[GitHub - antmelekhin/docker-systemd: Docker images with systemd support.](https://github.com/antmelekhin/docker-systemd)**
>
> Docker images with systemd support.

or on Docker Hub:

> **[antmelekhin/docker-systemd - Docker Image](https://hub.docker.com/r/antmelekhin/docker-systemd/tags)**

There are examples on how to use images with molecule in GitHub README.md. You can also check the DockerFiles to figure out how systemd enabled images are made… if you want to create your custom ones.

Great shout out to Anton Melekhin - [antmelekhin](https://github.com/antmelekhin) - for creating these.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [March 5, 2026, 10:47pm UTC](https://forum.ansible.com/t/how-to-setup-docker-container-to-test-systemd-when-using-molecule/45491/4 "2026-03-05T22:47:48Z")

</div>

I build my own images with Systemd for use with Molecule run via GitLab CI, see this thread for details:

> **[Docker executor with systemd](https://forum.gitlab.com/t/docker-executor-with-systemd/91393/3?u=chrisc)**
>
> 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,...
