February 22, 2023, 12:36pm
Do you know by any chance how to get container ID from within the container with cgroup v2? Tried to find a solution in google, problem is well-know (couple of topics on stackoverflow) but no solution as of now.
Perhaps someone has a working command?
February 22, 2023, 8:32pm
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
In aim to check if we are inside of container we need to type (it is taken from the web):
# docker container exec -it ub bash
root@8d6a3b7407c5:/# cat /proc/1/cgroup
‘ub’ is the name of Ubuntu Docker image.
Before I created container like that:
# docker container run -itd --name ub ubuntu:latest bash
As you can see inside of my container there is no any ‘docker’ word after the /. Why?
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
I cans ee multiple potential problems:
You should not use $(date +%Y-%m-%d-%H.%M.%S) multiple times, because the time between the two execution can change, so you will refer to a wrong container name.Save the result to a variable, and use the variable multiple times.
I am not sure if yoiu really wanted to do this: pwd & sudo docker ...
If you want to run your container in the background, you can just use the --detach or -d flag, but then you need to run a command in the container which keeps …
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.