Accessing tag as an environment variable inside a Docker container

I’d like to be able to access the tag/revision used to build a docker container from within that container. Is there a simple way to surface the tag/revision during the build as an environmental variable?

For example, I would like an API running inside a container to know its current revision. Without docker I would normally use git to write the revision to the a file that the API can access, but this doesn’t seem to be the “Docker way”.

  • Giving full access to eth1 to docker container
  • Assign static IP to Docker container
  • Understanding docker from a layman point of view
  • Could not find entity for dockerfile/elasticsearch
  • Dockerfile vs Docker image
  • How do share a directory with same name in the current directory with docker
  • run a meteor app on docker - doesn't open in localhost
  • Docker Selenium - Tests pass in Chrome but not Firefox
  • chown docker volumes on host (possibly through docker-compose)
  • How can I add the used base (FROM) image to a docker image
  • How to make nginx-docker container running always
  • Ansible Docker Module from OSX
  • 2 Solutions collect form web for “Accessing tag as an environment variable inside a Docker container”

    It is not an API, but you can always pass the tag with the -e of the run command. A short example $ docker run -it -e mytag=abc123 ubuntu:latest env | grep mytag
    mytag=abc123
    and so inside your container mytag will contain the tag of the container.

    This is now possible with docker build arguments.

    https://docs.docker.com/engine/reference/commandline/build/

    docker build --build-arg TAG=v0.0.1 .

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.