docker-node icon indicating copy to clipboard operation
docker-node copied to clipboard

Add new bare image tag

Open Aschen opened this issue 5 years ago • 5 comments

What does this PR do

This PR introduce a new image tag (name proposals: node:14-scratch, node:14-minimal, node:14-bare) which correspond to a minimal image containing only Node binary and it's dependencies (mostly the libstdc++ and musl).

The image size is 68.9MB which is 40% smaller than the 14-alpine3.10 image (117MB).

If you like the idea I will adds images for other Node version.

EDIT (2020/07/03):

This image is now based on alpine to benefits from the shell and package manager for only 5MB.
The image is 71MB.
I've renamed the image tag from scratch to bare.

Usage

This image can be used in a multi-stage build:

  • from the alpine image, build the application
  • from the bare image, just copy the files
FROM node:14-alpine3.10 as builder

COPY . /opt/kuzzle

RUN cd /opt/kuzzle && npm install --production

FROM node:14-bare

COPY --from=builder /opt/kuzzle /opt/kuzzle

CMD ["node", "/opt/kuzzle/bin/start-kuzzle-server"]

Why

When you go to production, you may want to deploy images containing only your application and not your build chain (npm, yarn). Also there is a lot of unnecessary files like documentation or c headers that you don't need either.

This could allows to save a lot of disk space but also bandwidth for people deploying Node.js applications.

How

Builder image steps description:

  • use the node 14 alpine 3.10 build steps to download and compile Node
  • strip node binaries
  • remove unnecessary files (NPM, headers, documentation, some binaries)

Then in the final image is built from alpine with only Node.js.

Aschen avatar Jun 26 '20 06:06 Aschen

I'm not sure whether this would match the multi-stage restrictions on official images or not https://github.com/docker-library/faq#multi-stage-builds

nschonni avatar Jun 26 '20 17:06 nschonni

If you can get a FROM scratch image down to ~68.9MB, shouldn't you be able to get the FROM alpine image down to ~74.47MB (given alpine:3.12 is only ~5.57MB)? :smile:

tianon avatar Jun 26 '20 17:06 tianon

where the necessary artifact does not exist and must be built from source and/or the build process is going to be similarly highly deterministic (thus mitigating the cache concern somewhat);

@nschonni From what I understand of this sentence, it would be better to directly add the Node binaries to the image rather than building them. If we don't have the choice to build them I'm not sure if we can consider Node build "highly deterministic"

@tianon The problem is I don't know how the users rely on what part of the existing alpine image so removing some part of the image may be a breaking change

Aschen avatar Jun 29 '20 03:06 Aschen

Following your comment @tianon I switch to use alpine image as base and I end up with a 71MB image. (I just saw that you are also the guy who answered me here :smile: )

I updated the original PR description.

Aschen avatar Jul 03 '20 03:07 Aschen

Any updates on this PR ?

Aschen avatar Jul 21 '20 04:07 Aschen