I am looking for a reliable method for detecting whether the docker socket inside a container, such as /var/run/docker.sock
, is injected from the docker host into the container using the -v
parameter (docker run -v /var/run/docker.sock:/var/run/docker.sock image-name:image-tag
) or is created by a docker daemon that is running inside the docker container ( run dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375
in the entrypoint of the docker container).
I want to underline that I want to check this inside the container not on the host machine.
My preferred solution would be a shell script that can be executed inside the container. The output might be a string such as "docker-in-docker" or "injected-socket" (depending on the detected mode).