2

Is it possible to copy multiple files to different locations in a Dockerfile?

I'm looking to go from:

COPY outputs/output/build/.tools /root/.tools
COPY outputs/output/build/configuration /root/configuration
COPY outputs/output/build/database/postgres /root/database/postgres

I have tried the following, but no joy:

COPY ["outputs/output/build/.tools /root/.tools","outputs/output/build/configuration /root/configuration","outputs/output/build/database/postgres /root/database/postgres"]

Not sure if this is even possible.

Jignesh Mistry
  • 2,221
  • 6
  • 25
  • 50
user3292394
  • 609
  • 2
  • 11
  • 24
  • 2
    If `COPY outputs/output/build/ /root/` or something along those lines doesn't do what you want, then no. – David Maze Jul 20 '18 at 16:23
  • 1
    I think you'll have to copy them all to a single destination and then `mv` them each manually. – zero298 Jul 23 '18 at 17:50
  • Possible duplicate of [How to copy multiple files in one layer using a Dockerfile?](https://stackoverflow.com/questions/30256386/how-to-copy-multiple-files-in-one-layer-using-a-dockerfile) –  Sep 11 '18 at 10:39
  • 1
    @user719662 no, it's not a duplicate of that question. That question pertains to copying multiple files to one location. This is about copying multiple files to multiple locations. – Betty Von Schmartenhausen May 20 '20 at 07:30

2 Answers2

0

Create a file .dockerignore in your docker build context directory. Create a soft link (ln) of the root directory you want to copy and exclude the directories you don't want in your .dockerignore.

In your case, you don't need the soft link as the directory is already in the docker build context. Now, add the directories in the .dockerignore file that you don't want eg. if you don't want bin directory you can do that as,

# this is .dockerignore file
outputs/output/build/bin*

Finally in your Dockerfile,

COPY outputs/output/build/ /root/

Details are here.

Sumsuddin Shojib
  • 3,583
  • 3
  • 26
  • 45
-2

it looks like you are trying to do bash style [] brace expansion RUN command uses sh NOT bash

see this SO article discussing it

Bash brace expansion not working on Dockerfile RUN command

or the docker reference

https://docs.docker.com/engine/reference/builder/#/run

Zee303
  • 32
  • 7
  • I'm not sure you understood the question. The question was *"Is it possible to copy multiple files to different locations in a Dockerfile?"* not "Why isn't this command working?". The OP tried the command with [ ] to no avail to accomplish the original problem. – Raid Aug 23 '20 at 08:19