Reputation: 1759
I want to know the version of docker when I'm inside a container.
I know that /proc/self/cgroup
can tell me if I'm in a container. But how about the version?
Thanks for any tips!
Upvotes: 1
Views: 2391
Reputation: 59896
The first and safe approach that I will recommend is to pass the docker version to the container as an environment variable.
docker run -e DOCKER_VERSION="$(docker -v)" -it --rm alpine sh -c "echo \$DOCKER_VERSION"
The second approach can be is to mount host docker-socket but you should know about this risk of docker-socket just for getting the version of docker.
docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock alpine ash -c "apk add --no-cache curl && curl --unix-socket /var/run/docker.sock http://localhost/version"
Upvotes: 0
Reputation: 1969
You can use the docker api from inside the container to query the docker engine https://docs.docker.com/develop/sdk/ specifically you can use this endpoint https://docs.docker.com/engine/api/v1.30/#operation/SystemVersion
Upvotes: 1
Reputation: 340
You can execute command on host machine while you are inside a container.
ssh -l ${USERNAME} ${HOSTNAME} "docker -v"
Upvotes: 1