Repository navigation
Description
- I have tried with the latest version of Docker Desktop
- I have tried disabling enabled experimental features
- I have uploaded Diagnostics
- Diagnostics ID:
Expected behavior
Systemd based services in containers should start, as they have always been doing in x86 computers
Actual behavior
Systemd based services in containers do not start on M1 / Silicon computers.
Information
Hi
I've recently been given a new M1 MBP laptop where I'm trying to run a docker image with systemd that we use as part of our CI build, but I'm not able to start it successfully. We have been building and running these containers in x86 MBP for years with success, so this seems to a platform specific issue with the new M1.
- macOS Version: Monterey 12.0.1
- Intel chip or Apple chip: Apple chip
- Docker Desktop Version: 4.3.0 (71786)
Steps to reproduce the behavior
Following the instructions at https://hub.docker.com/_/centos I've created a Centos Systemd ready container with the following Dockerfile:
FROM centos:7
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]
However, when running it I get the following error:
$ docker run --rm -ti --privileged -v /sys/fs/cgroup:/sys/fs/cgroup local/c7-systemd
Failed to insert module 'autofs4'
Failed to mount cgroup at /sys/fs/cgroup/systemd: Operation not permitted
systemd 219 running in system mode. (+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN)
Detected virtualization docker.
Detected architecture arm64.
Welcome to CentOS Linux 7 (AltArch)!
Set hostname to <6870484659ce>.
Initializing machine ID from random generator.
Cannot determine cgroup we are running in: No such file or directory
Failed to allocate manager object: No such file or directory
[!!!!!!] Failed to allocate manager object, freezing.
I've tried to use the DOCKER_DEFAULT_PLATFORM=linux/amd64 environment variable as well, but the output and behavior is mostly the same.
$ docker run --rm -ti --privileged -v /sys/fs/cgroup:/sys/fs/cgroup local/c7-systemd
Failed to insert module 'autofs4'
Failed to mount cgroup at /sys/fs/cgroup/systemd: Operation not permitted
systemd 219 running in system mode. (+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN)
Detected virtualization docker.
Detected architecture x86-64.
Welcome to CentOS Linux 7 (Core)!
Set hostname to <a2561af401fb>.
Initializing machine ID from random generator.
Failed to configure loopback device: Connection timed out
Cannot determine cgroup we are running in: No such file or directory
Failed to allocate manager object: No such file or directory
[!!!!!!] Failed to allocate manager object, freezing.
Some unsuccessful attempts I've done:
- different combinations of the
privilegedsetting and/sys/fs/cgroupmounts - adding tmpfs settings, as suggested at https://stackoverflow.com/questions/36617368/docker-centos-7-with-systemctl-failed-to-mount-tmpfs-cgroup
- tweak the cgroups settings
"exec-opts": ["native.cgroupdriver=systemd"], "cgroup-parent": "docker.slice", as suggested at https://serverfault.com/questions/1053187/systemd-fails-to-run-in-a-docker-container-when-using-cgroupv2-cgroupns-priva
Is there anything that can be done to overcome this issue?
Thanks!
Activity
wpwood commentedon Dec 3, 2021
I don't think that this is an M1 issue. I see something similar on an Intel Macbook when trying to run the official Ubuntu:18.04 image on 4.3.0.
From my docker compose log:
Dropping back to Docker Desktop 4.2.0 fixes the issue. I assume that it's related to the note in the 4.3.0 release notes:
If so, though, it's going to break a bunch of people on older images.
madrover commentedon Dec 3, 2021
Good catch @wpwood!
That new Docker Desktop version with the behavior change regarding systemd has been released exactly the same day I had my new M1 delivered. I was wondering why I wasn't seeing more reports about this matter, now I understand... hehehe
I haven't done much testing, but I've downgraded my M1 MBP Docker Desktop to 4.2.0 and systemd services seem correct when using an
aarch64andamd64centos:7containers, albeit considerably slower in the second (1'' vs 30'' aprox...). Next week I'll have a go on my Intel MBP and see how it behaves.The requirement of
systemd-247seems quite steep. At the time of writing not even Centos 8 stream has it, beingsystemd-239-51its current version, see https://pkgs.org/download/systemd. So, yeah, this is going to have a noticeable impact.elishagreenwald commentedon Dec 7, 2021
+1 to this. Is there any chance you'd consider an option which version of cgroups to use so you don't break backwards compatibility? I think some folks who are using systemd with centos7 will appreciate it although who runs systemd in docker containers?!? ✋ I do, lol.
djs55 commentedon Dec 8, 2021
Thanks for the report. It looks like the release note recommending 247 is overly pessimistic (perhaps relevant changes were backported?)
Here's a Dockerfile I tried (on Windows but I think Mac should be the same)
and here's what I ran:
I was able to open
localhost:8080in my browser.Could you try
docker pull centos:7? It might be that patches were backported and thesystemdversion bumped in the latest image.For reference I'm using
djs55 commentedon Dec 8, 2021
Looking more closely at your setup compared to mine, I think my command-line arguments are different:
vs
madrover commentedon Dec 9, 2021
Many thanks for your input @djs55, but I'm afraid it's not working for me, either on my arm64 nor x86 laptops. I'm using the same
Dockerfileand the output on both laptops is the same:On the other hand, I've tested the same with the same Dockerfile but using
centos:8and it works flawlessly. I guess the key difference is the usage of Cgroups v2, which does not seem to be enabled by default on Centos 7 but it does on Centos 8, see https://www.redhat.com/en/blog/world-domination-cgroups-rhel-8-welcome-cgroups-v2.Given that Centos 7 is still a supported and widely used platform, I would suggest to make the Cgroups V2 requirement in Docker for Mac optional. I don't have any data to back my assumption, but I would say that Centos 7 is still more prevalent than Centos 8 right now, specially with the the Centos license change which EOLs Centos 8 in a few weeks.
I'll downgrade Docker Desktop to 4.2.0 for now...
wbaweto commentedon Dec 10, 2021
you can see docker desktop 4.3.0 release notes: https://docs.docker.com/desktop/mac/release-notes/
Docker Desktop now uses cgroupv2. If you need to run systemd in a container then:
junoteam commentedon Dec 11, 2021
If anybody interested how to run Ubuntu 22:04 Docker with
systemdinside: rofrano/vagrant-docker-provider#5carlosabalde commentedon Dec 13, 2021
Temporarily downgrading to 4.2.0 here too. Is there any chance for that option to decide which version of cgroups to use?
carlosabalde commentedon Dec 13, 2021
I've shared a few notes in systemd/systemd#19760 (comment) that I think could be useful to other people landing in this case.
jamshid commentedon Dec 13, 2021
Just to be clear before this regression I could run systemd in a centos:7 container without
--privilegedand /sbin/init started fine --systemctl statusandrestartworked fine. I just had to add this docker-compose-override.yml with these additional settings for my container:While I know it's not good practice to run systemd in a container it's important for being able to simulate a "regular" environment using containers e.g. to run QA scripts that use systemctl. I believe podman advertises systemd compatibility, seems important to maintain parity.
djs55 commentedon Dec 14, 2021
As an experiment, could you try using this development build: https://desktop-stage.docker.com/mac/main/arm64/72295/Docker.dmg You will need to edit
~/Library/Group\ Containers/group.com.docker/settings.jsonto addoguizol commentedon Dec 14, 2021
I managed to make it work with the build for amd64 and with the settings update.
Thanks!
c-hoeger commentedon Dec 14, 2021
Would you mind providing such a dev snapshot build for x86_64 as well? Having the same problem now and only a downgrade to 4.2.0 solved my problem.
16 remaining items
madrover commentedon Jan 19, 2022
Since Docker 4.4.2 has been solved the current issue I will proceed to close it.
That said, I wholeheartedly agree about the above comments as well. Given the impact this issue has on the Docker community, I'd vouch to keep this capability to be available while the major distributions (eg Centos 7) that needs this functionality are still supported.
gtskaushik commentedon Jan 19, 2022
@madrover I think there is a typo. The setting is actually
RulerOf commentedon Jan 21, 2022
Figured I'd share since I took the time to write this. Here's a fix for MacOS you can paste into your terminal:
jamshid commentedon Jan 22, 2022
I can't get the setting
"deprecatedCgroupv1": true,or"deprecatedCgroupsv1": true,to stay in~/Library/Group Containers/group.com.docker/settings.json. That file gets overwritten at startup.Ok thanks @RulerOf that script seems to work, I don't know why. Anyone know what's going on with settings.json? It doesn't seem like all that should be necessary every time you restart Docker for Mac.
cgroups: fix typo, soften language around upgrading to v2
djs55 commentedon Jan 24, 2022
@elishagreenwald @aem12f @quacktacular and all: sorry for the typo in the release notes -- I've made a PR to correct it here: docker/docs#14166
I've also softened the language around upgrading containers to v2. I expect the downgrade of Docker to v1 will continue working (since the Docker engine itself is well-tested there), with 2 caveats:
I hope that sounds more reasonable!
@jamshid are you still seeing the
deprecatedCgroupv1setting revert on application restart?jamshid commentedon Jan 24, 2022
Thanks @djs55 correct I could not get the setting to stick. There's definitely something buggy there since @RulerOf had to make a script.
I just tried adding
"deprecatedCgroupv1": true,to~/Library/Group Containers/group.com.docker/settings.jsonand did Docker menu => Restart. The setting is still in the file butdocker inforeportsCgroup Driver: cgroupfsCgroup Version: 2.And when I Quit docker and Reopen it, the setting is removed from settings.json. Hopefully you see that?
Running the script above does add
"deprecatedCgroupv1": truebut same output fromdocker info:Cgroup Version: 2. Is that expected?Btw I'm trying to switch to cgroup V1 because I'm hoping it allows systemd in a container to work without
--cgroupns=host, which docker compose does not yet support (docker/compose#8167).dannystaple commentedon Feb 3, 2022
This whole thread turned out to be the key to concourse CI no longer working locally on a Mac. There are updates in the offing for concourse, but given that the next layer is possibly DinD stuff containers, and those may still not be on groups v2 yet, then using the script to set it is the best fix until these other projects release updated containers.
aem12f commentedon Feb 24, 2022
I'm not sure who needs to hear this, whether it's here or on docker/compose#8167, but I was able to successfully get systemd processes working on ubuntu 22.04 image which comes standard with systemd 249 using docker-compose on the latest version of docker desktop (4.5.0 as i'm on a mac). Ensure cgroup vol is rw and priv is true. the sentiment has been that we needed
cgroupns=hostfor this to work, but it has not been created as a valid flag for docker-compose. My current docker-compose setup along with relative volume paths was proving to be difficult to migrate to a docker run command. Maybe this could help someone- /sys/fs/cgroup:/sys/fs/cgroup:rwprivileged: truemyfreedev commentedon Mar 7, 2022
This may help, just upgrade the systemd to the latest version. I added these extra lines in my Dockerfile. No need to downgrade Docker desktop. Works well in my MacOS.
then run container,
docker run -ti --privileged --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw --name $DOCKER_CONTAINER_NAME -d -p 6600:22 local/test-centos7Implemented a temporary fix to make it work when cgroup v2 is required
docker-robott commentedon Apr 22, 2022
Closed issues are locked after 30 days of inactivity.
This helps our team focus on active issues.
If you have found a problem that seems similar to this, please open a new issue.
Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle locked