You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have created a my express server as a single executable apps using https://nodejs.org/api/single-executable-applications.html . Since it is a direct executable file now, I am trying to run it in a docker environment with minimal external dependencies.
A few ques,
Would the compiled binary still require a nodejs runtime? Can I use something like a simple scratch image to run the binary. (I tried but couldn't get it to work)
My end goal is to use multistage docker build process. I create my SEA using my main nodejs code. And then move the node executables to a second minimal image and run there. The multi build process ensures that noone can backtrack to first image layers and look at my code.
Something like this,
Use first base image to compile code to SEA
FROM node:alpine as builder
WORKDIR /app
COPY . .
RUN npm run build
All binaries will be saved in /build
RUN mkdir /build
RUN node --experimental-sea-config sea-configs/api.json
RUN cp $(command -v node) /build/api-node-app
RUN npx --yes postject /build/api-node-app NODE_SEA_BLOB --overwrite /build/api.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have created a my express server as a single executable apps using https://nodejs.org/api/single-executable-applications.html . Since it is a direct executable file now, I am trying to run it in a docker environment with minimal external dependencies.
A few ques,
Something like this,
Use first base image to compile code to SEA
FROM node:alpine as builder
WORKDIR /app
COPY . .
RUN npm run build
All binaries will be saved in /build
RUN mkdir /build
RUN node --experimental-sea-config sea-configs/api.json
RUN cp $(command -v node) /build/api-node-app
RUN npx --yes postject /build/api-node-app NODE_SEA_BLOB --overwrite /build/api.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
Stage 2: Create the final minimal image
FROM gcr.io/distroless/nodejs22-debian12
WORKDIR /app
COPY --from=builder /build /app
Set the default command to run your API binary
CMD ["/app/api-node-app"]
Beta Was this translation helpful? Give feedback.
All reactions