Search code examples
dockerdockerfiledocker-copy

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


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.


Solution

  • 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.