Catalogue
Setting Up Node.js on an Alpine Image with a Multi-Stage Build

Setting Up Node.js on an Alpine Image with a Multi-Stage Build

🌐 日本語で読む

When setting up Node.js on a PHP Alpine base image,
you can install it with apk add nodejs,
but you can also achieve it by copying the files needed to run Node from the Node Alpine image using a multi-stage build, which keeps the configuration simple.

1
2
3
4
5
6
7
8
9
10
FROM node:16.15.1-alpine AS node

FROM php:8.0.19-fpm-alpine AS main

# Copy the files required to set up Node.js from the node image
COPY --from=node /usr/lib /usr/lib
COPY --from=node /usr/local/share /usr/local/share
COPY --from=node /usr/local/lib /usr/local/lib
COPY --from=node /usr/local/include /usr/local/include
COPY --from=node /usr/local/bin /usr/local/bin

That’s all.
I hope this is helpful.

Setting Up Node.js on an Alpine Image with a Multi-Stage Build

https://kenzo0107.github.io/en/2022/08/24/setup-nodejs-on-alpine/

Author

Kenzo Tanaka

Posted on

2022-08-24

Licensed under