How to get container ID from within the container with cgroup v2

Can you share why you need to know the container id inside the container itself?

I remembered an issue wich was related to cgroup v2 and commands in the container, I am not sure that helps, but I leave it here anyway

And now that I shared this link I realized I already answered a question related to getting the container id which might help you as well

You could for example save the cid file in a folder that is mounted into the container so you just read a file in the container that you mounted.