DEV Community

Cover image for ALL environment variables available in the Docker Hub build environment

ALL environment variables available in the Docker Hub build environment

Juan Julián Merelo Guervós
Coder of code, writer of writings.
・2 min read

The Docker Hub documentation lists all these environment variables, which are available in your scripts in that environment:

    SOURCE_BRANCH: the name of the branch or the tag that is currently being tested.
    SOURCE_COMMIT: the SHA1 hash of the commit being tested.
    COMMIT_MSG: the message from the commit being tested and built.
    DOCKER_REPO: the name of the Docker repository being built.
    DOCKERFILE_PATH: the dockerfile currently being built.
    DOCKER_TAG: the Docker repository tag being built.
    IMAGE_NAME: the name and tag of the Docker repository being built. (This variable is a combination of DOCKER_REPO:DOCKER_TAG.)
Enter fullscreen mode Exit fullscreen mode

However, there are quite a few more, which might be useful in a certain environment; these were discovered by just printing the environment variables via a Perl script (which, BTW, you can use in Docker Hub for your own purposes).

  • SOURCE_TYPE: this one seems to contain git. It might be different if it's pushed directly, or via the API.
  • PATH: is the regular system PATH. It contains /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.
  • MAX_LOG_SIZE: it contains 67108864. Not clear if it can be changed.
  • BUILD_CODE: no idea what this is. It contains a code.
  • PUSH: it contains true if it's been created via PUSH. Probably other values if it's been automatically launched.
  • GIT_TAG and GIT_SHA1: no idea what the first one is, the second is the commit SHA1.
  • HOSTNAME: the host it's using to build.
  • DOCKER_HOST: the socket the client is using to connect, same as in the local docker installation.
  • There's something called SIGNED_URLS, which holds Amazon urls. No idea what this is, or how it can be useful.
  • DOCKER_TAG and CACHE_TAG, the tag that's being built, like latest.
  • PYTHONUNBUFFERED is equal to 1.
  • SOURCE_REPOSITORY_URL the repository it's being built from.
  • DOCKER_CFG contains information on the user, including user tokens.

Out of all these, you can probably use PUSH or even GIT_SHA1 to introspect what's being built, and maybe take some actions. For instance, along with information on the last build you could create a script that built only those Dockerfiles that have changed.

Discussion (0)