Enabling Cgroup2 on Azure Ubuntu

Published by moxlotus on

Due to the recent change of job, I had to set up all the DevOps infrastructure from scratch which includes Gitlab, Docker, Jenkins and various other tools. As I have been a software engineer most of the time for the last 5 years plus, DevOps is really something that I do on my homelab as a hobby. In my new job, I am able to put this hobby into real test.

Unlike my homelab setup, there are various additional considerations required regarding security and robustness of the system. One of the thing that I have set up in the company is the use of rootless docker which mitigates security issues related to docker containers. However, with this setup, there are various new problems that appeared. One of them is the setting of cpu and memory of the docker container.

This wasn't really a problem until I had to set up docker based build agent on Jenkins which requires me to enable cgroup v2 on the kernel. And the instruction from rootlesscontainers isn't really helpful. It doesn't really tells me where I am suppose to put "systemd.unified_cgroup_hierarchy=1". So after some searching on the internet, I have found my solution.

In short, if you are running ubuntu vm on Azure, you should add that line to the file, /etc/default/grub.d/50-cloudimg-settings.cfg. In the variable called "GRUB_CMDLINE_LINUX". After which, you will simply need to reboot your OS and you should see under your docker info that you are using cgroup version 2.

Share it with others