An yarn
cache compatible Dockerfile, for building node.js images faster.
Clone this gist into your project root, and add it to your source control.
Change the image service-name:latest
tag to your project name in the Dockerfile
and build.sh
files.
Then, always build your image using the build.sh
script.
$ chmod +x ./build.sh
$ ./build.sh
@etgrieco, thanks for sharing. It works for me. One limit in the solution is that IDE can't use node modules(for type hints or other function) because the modules do not exist in the project folder.
My workaround is replacing this line:
- node_modules_cache:/app/node_modules
with- .:/app:cached
, and node modules show in the project folder. Doing this works fine with IDE, but another problem comes - every time I runyarn add <package>
, it seems to reinstall all packages without using Yarn cache.Do you have any idea about this problem? Maybe I missed something or use this in the wrong way.
FYI, I don't use docker compose. I use docker CLI instead: