Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile COPY {source:-...}

When you create a project in Visual Studio 2017 with Docker support, the Dockerfile has the following line:

COPY ${source:-obj/Docker/publish} . 

What does it mean? Where does the source macro point to? What is the meaning of the dash?

like image 377
zuraff Avatar asked Apr 14 '17 21:04

zuraff


People also ask

What is the Copy command in Dockerfile?

The Copy Command COPY is a dockerfile command that copies files from a local source location to a destination in the Docker container. A Dockerfile is a text file with instructions to set up a Docker container.

What does Workdir do in Dockerfile?

The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.

What is && in Dockerfile?

Each RUN command in a Dockerfile creates a new layer to the Docker image. In general, each layer should try to do one job and the fewer layers in an image the easier it is compress. This is why you see all these '&& 's in the RUN command, so that all the shell commands will take place in a single layer.


1 Answers

That is called variable substitution.

In English, it translates to this:
"Hey Docker, when you build this, COPY the path you find the in $source variable in to the current directory in the image (.). If $source is empty or absent, just use the default path obj/Docker/publish"

$source is an environment variable that is defined before executing docker build.

Some references:

  • Docker documentation
  • Bash variable substitutions
like image 187
Ayman Nedjmeddine Avatar answered Sep 24 '22 23:09

Ayman Nedjmeddine