/ docker

Alpine Docker Image with Node-SASS

Level - Intermediate. Read Time ~ <5 minute.

Recently I spent several fun hours of my life trying to build an Alpine Linux Docker image with Node-SASS installed.

So the tools and tech I'm covering here are the following: -

The reason for wanting an Alpine image with Node-SASS installed was the for these reason. Small disk footprint, secure, base layer for building Node applications, NPM 5 and the latest version of Node. I won't go into the specifics or all the reasons/benefits of using Alpine linux, you can read the above link. But it achieves what we desired.

Thought I would share this as someone else may be battling the same challenges. If this helps even one person, I'll be pleased.

Can find it at the following locations: -

Any comments leave below or on GitHub or Docker Hub.

In case the above become unreachable in the future, here is the Dockerfile: -

FROM node:8.11.0-alpine

RUN apk update && \
    apk upgrade && \
    apk add git g++ gcc libgcc libstdc++ linux-headers make python && \
    apk update && \
    npm install -g npm5

# install libsass
RUN git clone https://github.com/sass/sassc && cd sassc && \
    git clone https://github.com/sass/libsass && \
    SASS_LIBSASS_PATH=/sassc/libsass make && \
    mv bin/sassc /usr/bin/sassc && \
    cd ../ && rm -rf /sassc

# created node-sass binary
ENV SASS_BINARY_PATH=/usr/lib/node_modules/node-sass/build/Release/binding.node
RUN git clone --recursive https://github.com/sass/node-sass.git && \
    cd node-sass && \
    git submodule update --init --recursive && \
    npm install && \
    node scripts/build -f && \
    cd ../ && rm -rf node-sass

# add binary path of node-sass to .npmrc
RUN touch $HOME/.npmrc && echo "sass_binary_cache=${SASS_BINARY_PATH}" >> $HOME/.npmrc

ENV SKIP_SASS_BINARY_DOWNLOAD_FOR_CI true
ENV SKIP_NODE_SASS_TESTS true