dockerdockerfiledocker-copy

COPY with docker but with exclusion


In a Dockerfile, I have

COPY . .

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

Something like this:

   COPY [all but **/node_modules/**] .

Is this possible with Docker?


Solution

  • Create file .dockerignore in your docker build context directory (so in this case, most likely a directory that is a parent to node_modules) with one line in it:

    **/node_modules
    

    although you probably just want:

    node_modules
    

    Info about dockerignore: https://docs.docker.com/engine/reference/builder/#dockerignore-file