How to copy multiple files in one layer using a Docker file to different locations?

13.9k Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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.

1
On

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