Is it possible to get the current image tag inside a running container? Currently I am passing an environment variable with the same name as the tag, but it would be nice if I could somehow read it from a docker supplied environment variable.
<name>/<image>:<tag>
I am doing a sed
in a config based on the <tag>
.
To check the labels of a particular Image, you can use the Docker Inspect command. Start the Docker Container. Execute the Inspect Command. Inside the LABELS object, you can find all the labels associated with the image that you have specified inside your Dockerfile.
Docker tags are mutable named references to Docker images, much like branch refs in Git. They make it easy to pull and run images, and for image authors to roll out updates automatically. For example, to pull the latest Debian GNU/Linux image for the buster release: $ docker pull debian:buster.
Docker tags are just an alias for an image ID. The tag's name must be an ASCII character string and may include lowercase and uppercase letters, digits, underscores, periods, and dashes. In addition, the tag names must not begin with a period or a dash, and they can only contain 128 characters.
If you don't mind adding curl and jq to the container and also mounting the docker socket , you can retrieve the image by running the following script inside the container:
#!/bin/bash
CONTAINER_ID=$(head -1 /proc/self/cgroup | rev | cut -d/ -f 1 | rev)
curl --unix-socket /var/run/docker.sock http:/v1.40/containers/{$CONTAINER_ID}/json | jq .Config.Image
The first line gets the container id from /proc/self/cgroup and the second uses docker api to inspect the container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With