COPY with docker but with exclusion

前端 未结 7 2108
轮回少年
轮回少年 2020-12-12 11:48

In a Dockerfile, I have

COPY . .

I want to exclude an entire directory, in my case, node_modules directory.

Something like this:

相关标签:
7条回答
  • 2020-12-12 12:50

    For those who can't use a .dockerignore file (e.g. if you need the file in one COPY but not another):

    Yes, but you need multiple COPY instructions. Specifically, you need a COPY for each letter in the filename you wish to exclude.

    COPY [^n]*    # All files that don't start with 'n'
    COPY n[^o]*   # All files that start with 'n', but not 'no'
    COPY no[^d]*  # All files that start with 'no', but not 'nod'
    

    Continuing until you have the full file name, or just the prefix you're reasonably sure won't have any other files.

    0 讨论(0)
提交回复
热议问题