Search code examples
dockerjenkinsdockerfilenode-modulesglob

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.


Solution

  • 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.