Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 534
Alexander Mills Avatar asked May 02 '17 21:05

Alexander Mills


People also ask

What is difference between ADD and COPY in Docker?

COPY is a docker file command that copies files from a local source location to a destination in the Docker container. ADD command is used to copy files/directories into a Docker image. It only has only one assigned function. It can also copy files from a URL.

Does Docker COPY overwrite?

It seems that docker build won't overwrite a file it has previously copied. I have a dockerfile with several copy instructions, and files touched in earlier COPY directives don't get overwritten by later ones. After building this, $BASE/config/thatfile. yml contains the contents of file1.

How do I manually COPY a docker image?

In order to transfer a Docker image from one server to another, what you need to do is first export the image to a file, then copy that file over from your current server to the new one using scp or rsync and finally load the image to your new server.

What is the use of Docker ignore?

dockerignore file allows you to exclude files from the context like a . gitignore file allow you to exclude files from your git repository. It helps to make build faster and lighter by excluding from the context big files or repository that are not used in the build.


1 Answers

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

like image 90
vith Avatar answered Sep 23 '22 18:09

vith