Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Introducing a much slimmer image (23.3MB instead of 75.3MB) for node:10-alpine-slim #1048

Closed
pascalandy opened this issue Jun 10, 2019 · 4 comments
Labels

Comments

@pascalandy
Copy link

pascalandy commented Jun 10, 2019

Hi folks,

I propose we create a node-slim for alpine. I was optimized my Dockerfile for Ghost and I found a way to not include yarn, npm, npx. I also compressed node using upx.

Here is the result.

size

devmtl/10.16-alpine-slim    latest              e5efb0afa59d        6 seconds ago       23.3MB
node                        10.16-alpine        9dfa73010b19        5 days ago          75.3MB

The beauty here is that it's all based on the official node:10.16-alpine image.

dockerfile

ARG ALPINE_VERSION="3.9"
ARG NODE_VERSION="10.16-alpine"

# Node official layer
### ### ### ### ### ### ### ### ### ### ###
FROM node:${NODE_VERSION} AS node-official

WORKDIR /usr/local/bin

RUN set -eux                                                      && \
    apk --update --no-cache add \
      upx                                                         && \
    upx node                                                      ;
    # node size / before=39.8MO, after=14.2MO
    # Thanks for the idea https://github.com/mhart/alpine-node/blob/master/slim/Dockerfile :)

# Node slim layer (about 50MO lighter)
### ### ### ### ### ### ### ### ### ### ###
FROM alpine:${ALPINE_VERSION} AS node-slim

LABEL org.label-schema.ghost.node-version="${NODE_VERSION}"       \
      org.label-schema.ghost.alpine-version="${ALPINE_VERSION}"   \
      org.label-schema.ghost.maintainer="${MAINTAINER}"           \
      org.label-schema.schema-version="1.0"

RUN set -eux                                                      && \
# setup node user and group
    addgroup -g 1000 node                                         \
    && adduser -u 1000 -G node -s /bin/sh -D node                 ;

# install node without yarn, npm, npx, etc.
COPY --from=node-official /usr/local/bin/node /usr/bin/
COPY --from=node-official /usr/lib/libgcc* /usr/lib/libstdc* /usr/lib/

in production

You can see how I use this in production to build Ghost.

conclusion

I know Dockerhub doesn't support multi-stage builds at the moment, but it's not the point. The point is to include only the library needed to run our node apps in PROD.

If slim is not the right term, I don't mind. This image does not include npm, yarn. It also compress the node binary with UPX.

Thanks for considering :)

@pascalandy
Copy link
Author

Just found this old issue. I think I have better arguments now :)

@nschonni
Copy link
Member

Think "slim" currently has a different meaning (ex: the other "slim" still have npm/yarn). There is an separate issue discussing variants without NPM/Yarn #404

@pascalandy
Copy link
Author

Thanks for pointing out #404 :)

@pascalandy pascalandy changed the title FEAT: Introducing node:10.16-alpine-slim (23.3MB instead of 75.3MB) FEAT: Introducing a much slimmer image (23.3MB instead of 75.3MB) for node:10-alpine-slim Sep 29, 2019
@nschonni nschonni closed this as completed Nov 5, 2020
@pascalandy
Copy link
Author

Allllright

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants