x300n
x300n

Reputation: 331

How to serve nodejs app using distroless image in Dockerfile?

I am trying to build this example into a distroless image: https://github.com/docker-hy/frontend-example-docker

Using vanilla image it would build and run like following:

FROM node:10

COPY . .  

RUN npm install
EXPOSE 5000
CMD ["npm", "start"]

The following won't work because npm isn't there!

FROM node:10 AS builder
COPY . /app
WORKDIR /app
RUN npm install

FROM gcr.io/distroless/nodejs:10
COPY --from=builder /app /app
WORKDIR /app
EXPOSE 5000
CMD ["npm", "start"]

How do I use distroless images to serve apps like the above example?

Upvotes: 1

Views: 11290

Answers (1)

josh.trow
josh.trow

Reputation: 4901

The Google documentation seems pretty clear on this, you could just copy/paste their Dockerfile from https://github.com/GoogleContainerTools/distroless/blob/master/examples/nodejs/Dockerfile

The relevant bit though is this being the 'second stage' - note no NPM command!

FROM gcr.io/distroless/nodejs:10
COPY --from=build-env /app /app
WORKDIR /app
CMD ["hello.js"]

Further, as docs for that specific image on say, the ENTRYPOINT is defined as 'node' for this image, so you should be passing effectively whatever script your 'npm run start' command is calling to kick off.

Upvotes: 4

Related Questions