Docker build-arg and copy

When trying to copy the contents of the folders, it works when I hardcode the path like this:

COPY ./my-folder /path/to/location

      

But one needs to be able to change this path, so I tried to use the build argument like this:

COPY ${folderVariable} /path/to/location

      

and then build with

--build-arg folderVariable=./my-folder

      

But it copies everything in the same folder as "my folder" when I only want the contents of "my folder"

+3


source to share


1 answer


You need to define it with ARG

in Dockerfile

before using:

FROM alpine:3.3

ARG folderVariable=./my-folder # Optional default value to be `./my-folder`

COPY ${folderVariable} /opt/my-folder

      

And build it like:



docker build --build-arg folderVariable=./folder-copy -t test .

      

See below for details: https://github.com/docker/docker/blob/master/docs/reference/builder.md#arg

+4


source







All Articles