Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionally ignoring a .dockerignore file on COPY

I have a front end build that uses variations of a Dockerfile for multiple steps: dev, CI (with Jenkins), and production. I'd like to not successively download node_modules for CI and production build images (both of which happen successively on the same box). Dev's node_modules are hosted on a volume to lower the overhead of restarting the dev container.

The three stages all share the same .dockerignore file which has a line excluding node_modules. Is it possible to add node_modules in via something like COPY node_modules/* node_modules/? I've searched in vain for a way to use a bind mount during the build portion of both CI and production builds. This doesn't seem to be possible.

like image 266
wegry Avatar asked Jan 20 '18 09:01

wegry


People also ask

How do you ignore files that are irrelevant to the Docker build?

dockerignore file is used to ignore files and folders when you try to build a Docker Image. You can specify the list of files and directories inside the . dockerignore file.

Is Dockerignore same as Gitignore?

dockerignore file is very similar to the . gitignore file in that it allows you to specify a list of files or directories that Docker is to ignore during the build process.

Where is Docker ignore file?

dockerignore file is on the root directory of your context, it will ignore it if it is somewhere in the subfolder.

Does Docker ignore Dockerfile?

The documentation says that yes it can. You can even use the . dockerignore file to exclude the Dockerfile and . dockerignore files.


1 Answers

Currently there is no such way where you can provide a different .dockerignore file.

As an alternative, you can copy the node_modules to a different directory such as ./node_new_module using cp on the host OR probably integrate that cp command in your CI.

After that you can use the new ./node_new_module to copy node modules in your Dockerfile -

COPY ./node_new_modules/* node_modules/

Hope this helps or gives you a way to solve this problem.

like image 186
vivekyad4v Avatar answered Oct 03 '22 15:10

vivekyad4v