22

When creating a new ASP.NET Core 3 project in Visual Studio for Mac, and then right clicking the project and selecting Add - Docker Support, IDE add docker-compose project to the solution and scaffolds the dockerfile for the API project.

docker-compose has the following entry by default:

services:
  project-name:
    image: ${DOCKER_REGISTRY-}projectname
  ...

It works out of the box, dockerfile gets processed, compose is called, all good. But what entity during the "compose up + debug" process defines the value for DOCKER_REGISTRY variable?

Pang
  • 9,564
  • 146
  • 81
  • 122
Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174

2 Answers2

11

It is an environment var on your pc or remote server, try to type :

$ echo $DOCKER_REGISTRY

the docker entry means "If variable DOCKER_REGISTRY is not set or null, use default", then it is prepended to your project name.

See https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02 for parameters expansion

kitensei
  • 2,510
  • 2
  • 42
  • 68
  • I think this isn't quite correct. `${DOCKER_REGISTRY-}` will only test for a value of `DOCKER_REGISTRY` not being set, and will not test if it's null, according to this - https://stackoverflow.com/a/32675207/1549918. So in theory, the default value for `DOCKER_REGISTRY` will only be used if the environment variable isn't set. – Chris Halcrow Mar 22 '22 at 00:05
  • 1
    See also: https://docs.docker.com/compose/compose-file/#interpolation – Wouter May 02 '22 at 15:29
  • The link for parameter expansion is helpful – Rosdi Kasim Nov 03 '22 at 03:37
7

From the documentation: https://docs.docker.com/compose/compose-file/#interpolation

${VARIABLE-default} evaluates to default only if VARIABLE is unset in the environment.

In the case of your generated file ${DOCKER_REGISTRY-}projectname

  • If DOCKER_REGISTRY is set, say to "docker.io/"
    • The image name would be "docker.io/projectname"
  • If DOCKER_REGISTRY is NOT set
    • The image name would be "projectname"
      • This shorthand name, also defaults to docker registry so you won't see difference unless you set DOCKER_REGISTRY to something other than the default registry.

what entity during the "compose up + debug" process defines the value for DOCKER_REGISTRY variable?

I don't think it is defining a value for the variable. It is setting your compose file to SUPPORT the setting of using DOCKER_REGISTRY to consistently control same registry for all images used.

Matt Mazzola
  • 4,593
  • 4
  • 22
  • 28