What is the dollar sign in the docker compose file?

Viewed 457

I just created a new dotnet core project and added docker support as well as orchestration support similar to what this MSDN tutorial describes.

The docker compose file looks as follows. Here generator31 is the name of the Visual Studio project that I created.

version: '3.4'

services:
  generator31:
    image: ${DOCKER_REGISTRY-}generator31
    build:
      context: .
      dockerfile: generator31/Dockerfile

What is this DOCKER_REGISTRY here. Also what is the $ sign doing there. Where can I get more info about that.

When I run the command

docker-compose up 

The image that's finally generated is generator31:latest

What's intriguing here is when I removed ${DOCKER_REGISTRY-} from the docker file to look like the following,

services:
  generator31:
    image: generator31
    .....Rest omitted for brivity

the result is exactly the same. The final image is again generator31:latest.

So I am not clear whats DOCKER_REGISTRY is doing here.

1 Answers

DOCKER_REGISTRY is the reference to Docker register, when you push or pull the image.

To access the environment variable in docker-compose it uses $ sign.

Prefix the image name with the Docker Hub username (for example, dockerhubusername/hellodockertools) if the image is pushed to the registry. Alternatively, change the image name to include the private registry URL (for example, privateregistry.domain.com/hellodockertools) depending on the configuration.

visual-studio-tools-for-docker

So I am not clear whats DOCKER_REGISTRY is doing here.

During build it will not show as because it just showing docker image name, and by default, docker does not show registry URL until its default docker registry.

To check this DOCKER_REGISTRY change the value and then run below command so you will privateregistry.domain.com/hellodockertools

docker images

DOCKER_REGISTRY is just an environmental variable defining target docker registry. That is, where would you like to put the image. It defaults to an empty string, but you can e.g. set it to your dockerhub registry in case you’d like to push the image there.

docker-compose-in-visual-studio-explained

For example, you want to push image aws ECR or azure, then overriding DOCKER_REGISTRY will help you to push the image to registry without changing anything in docker-compose.

export DOCKER_REGISTRY=aws.ecr.myimage/test && docker-compose push
Related