How to copy folders to docker image from Dockerfile?

后端 未结 10 651
走了就别回头了
走了就别回头了 2021-01-31 01:41

I tried the following command in my Dockerfile: COPY * / and got mighty surprised at the result. Seems the naive docker code traverses the directories from the glob

10条回答
  •  生来不讨喜
    2021-01-31 02:22

    As mentioned in your ticket:

    You have COPY files/* /test/ which expands to COPY files/dir files/file1 files/file2 files/file /test/.
    If you split this up into individual COPY commands (e.g. COPY files/dir /test/) you'll see that (for better or worse) COPY will copy the contents of each arg dir into the destination directory. Not the arg dir itself, but the contents.

    I'm not thrilled with that fact that COPY doesn't preserve the top-level dir but its been that way for a while now.

    so in the name of preserving a backward compatibility, it is not possible to COPY/ADD a directory structure.

    The only workaround would be a series of RUN mkdir -p /x/y/z to build the target directory structure, followed by a series of docker ADD (one for each folder to fill).
    (ADD, not COPY, as per comments)

提交回复
热议问题