I can create a docker container with PHP and composer with this:
FROM php:fpm
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
Is there any equivalent way to archive the same for node.js and npm? The only solutions I figured so far are:
If I use the last method, the container gets bloated in size as I copy everything over (around 908 MB). So I wonder if there is a smarter way. What folders/files would I have to copy over to just implement node and npm functionality?
For node and npm to work you have to copy two directories in your Dockerfile:
# Get NodeJS
COPY --from=node:20-slim /usr/local/bin /usr/local/bin
# Get npm
COPY --from=node:20-slim /usr/local/lib/node_modules /usr/local/lib/node_modules
I used this:
COPY --from=node:18.16.0-slim /usr/local /usr/local
Update: edited my answer so that copies the whole /usr/local folder instead of only /usr/local/bin. If you want to be more precise and save space (looks like 500MB), see @andreasm 's answer and copy the bin and lib/node_modules folders specifically.
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