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.
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.
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.
dockerignore file is on the root directory of your context, it will ignore it if it is somewhere in the subfolder.
The documentation says that yes it can. You can even use the . dockerignore file to exclude the Dockerfile and . dockerignore files.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With