1

I want to combine 2 COPY in one line with other source and destinations.

My current code:

COPY ./file1.txt /first/path/
COPY ./file2.txt /second/path/

I want combine these lines in one line. I tried with an array, but it's not correct:

COPY ["./file1.txt", "/first/path/", "./file2.txt", "/second/path/"]
Adriaan
  • 17,741
  • 7
  • 42
  • 75

2 Answers2

0

you can use a multi-line COPY statement and specify multiple src and dest pairs:

like this COPY ./file1.txt /first/path/ ./file2.txt /second/path/

This will copy file1.txt to /first/path/ and file2.txt to /second/path/.

or

COPY --from=0 ./file1.txt /first/path/ --from=0 ./file2.txt /second/path/

This will also copy file1.txt to /first/path/ and file2.txt to /second/path/.

Gourav
  • 9
  • 2
0

The COPY and ADD steps can have multiple source arguments, but only a single destination. When that syntax is used, the following requirement applies:

If multiple <src> resources are specified, either directly or due to the use of a wildcard, then <dest> must be a directory, and it must end with a slash /.

For more details, see the Dockerfile documentation: https://docs.docker.com/engine/reference/builder/#copy

BMitch
  • 231,797
  • 42
  • 475
  • 450