Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Add support for cgroupns_mode #166

Merged
merged 1 commit into from
Sep 2, 2022

Conversation

twouters
Copy link
Contributor

This fixes systemd support in Debian >=11 containers.

Minimal platforms configuration in molecule.yml:

platforms:
  - name: instance
    image: debian:bullseye
    command: /lib/systemd/systemd
    privileged: true
    cgroupns_mode: private

Example Dockerfile.j2:

FROM debian:bullseye

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y python3 sudo bash ca-certificates \
        iproute2 python3-apt aptitude
RUN apt-get update && apt-get install -y systemd; \
        systemctl mask [email protected]; \
        systemctl mask systemd-timesyncd.service;
RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
    /etc/systemd/system/*.wants/* \
    /lib/systemd/system/local-fs.target.wants/* \
    /lib/systemd/system/sockets.target.wants/*udev* \
    /lib/systemd/system/sockets.target.wants/*initctl* \
    /lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup* \
    /lib/systemd/system/systemd-update-utmp*

@twouters
Copy link
Contributor Author

This change doesn't seem to be required at all, the provided examples also work without the cgroupns_mode flag. 🤷‍♂️

@twouters twouters closed this Aug 18, 2022
@vincentstchu
Copy link

Hi @twouters, I think this PR could be helpful with docker for mac ansible/molecule#3349

@twouters twouters reopened this Sep 1, 2022
@twouters
Copy link
Contributor Author

twouters commented Sep 1, 2022

Could be that this change is still required for mac, as commented above.

@zhan9san zhan9san added the feature This issue/PR relates to a feature request. label Sep 2, 2022
@zhan9san
Copy link
Member

zhan9san commented Sep 2, 2022

@twouters

Thank you for contribution.

Could you add doc in https://github.com/ansible-community/molecule-docker/blob/main/src/molecule_docker/driver.py#L56?

It would be great if you can add some description about this option.

@twouters twouters force-pushed the feature/cgroupns_mode branch from 76484e2 to 6a1b49a Compare September 2, 2022 07:47
@twouters
Copy link
Contributor Author

twouters commented Sep 2, 2022

Added some very very brief docs

This fixes systemd support in Debian >=11 containers.

Minimal platforms configuration in `molecule.yml`:

```
platforms:
  - name: instance
    image: debian:bullseye
    command: /lib/systemd/systemd
    privileged: true
    cgroupns_mode: private
```

Example `Dockerfile.j2`:

```
FROM debian:bullseye

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y python3 sudo bash ca-certificates \
        iproute2 python3-apt aptitude
RUN apt-get update && apt-get install -y systemd; \
        systemctl mask [email protected]; \
        systemctl mask systemd-timesyncd.service;
RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
    /etc/systemd/system/*.wants/* \
    /lib/systemd/system/local-fs.target.wants/* \
    /lib/systemd/system/sockets.target.wants/*udev* \
    /lib/systemd/system/sockets.target.wants/*initctl* \
    /lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup* \
    /lib/systemd/system/systemd-update-utmp*
```
@zhan9san zhan9san force-pushed the feature/cgroupns_mode branch from a8b8eb7 to d75c6d8 Compare September 2, 2022 16:13
@zhan9san
Copy link
Member

zhan9san commented Sep 2, 2022

@twouters

Thanks for your work.

I tested it on my Mac, and it works like a charm with cgroupv2 on Docker Desktop for Mac.

Related to

  1. Host debian 11 running molecule on Debian 11 (Failed to connect to bus: No such file or directory) ansible/molecule#3632
  2. using this on debian 11 aka. bullseye is resulting in a non-systemd  geerlingguy/docker-debian11-ansible#4

The example for cgroupv2 is as below.

❯ cat molecule/default/molecule.yml
---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: instance
    image: geerlingguy/docker-debian11-ansible:latest
    command: ${MOLECULE_DOCKER_COMMAND:-""}
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
    pre_build_image: true
    privileged: true
    cgroupns_mode: host
provisioner:
  name: ansible
verifier:
  name: ansible

IMPORTANT:

  1. It's /sys/fs/cgroup:/sys/fs/cgroup:rw instead of /sys/fs/cgroup:/sys/fs/cgroup:ro
  2. Ensure cgroupns_mode: host exist.

@zhan9san zhan9san merged commit 719da14 into ansible-community:main Sep 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue/PR relates to a feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants