skip to Main Content

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/"]

2

Answers


  1. 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/.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search