Skip to content

Instantly share code, notes, and snippets.

@afoninsky
Last active January 11, 2017 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afoninsky/d6cbde798b56608e8563ac9b679ad4e3 to your computer and use it in GitHub Desktop.
Save afoninsky/d6cbde798b56608e8563ac9b679ad4e3 to your computer and use it in GitHub Desktop.
chinese dockerfile
### docker image with chinese mirrors (able to build in China directly)
FROM alpine:3.5
MAINTAINER Andrey <vkfont@gmail.com> Afoninsky
ENV VERSION=v7.4.0
ENV CONFIG_FLAGS="--fully-static --without-npm"
# add chinese mirrors
RUN truncate -s 0 /etc/apk/repositories && \
echo 'https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.5/main' >> /etc/apk/repositories && \
echo 'https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.5/community' >> /etc/apk/repositories
RUN apk add --no-cache curl make gcc g++ python linux-headers paxctl libgcc libstdc++ gnupg ca-certificates openssl git && \
update-ca-certificates && \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys \
9554F04D7259F04124DE6B476D5A82AC7E37093B \
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \
FD3A5288F042B6850C66B31F09FE44734EB7990E \
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
B9AE9905FFD7803F25714661B63B535A4C206CA9
# install nodejs and free empty space
# https://github.com/docker/docker/issues/2011
RUN curl -o node-${VERSION}.tar.gz -SL https://npm.taobao.org/mirrors/node/${VERSION}/node-${VERSION}.tar.gz && \
curl -o SHASUMS256.txt.asc -sSL https://npm.taobao.org/mirrors/node/${VERSION}/SHASUMS256.txt.asc && \
gpg --verify SHASUMS256.txt.asc && \
grep node-${VERSION}.tar.gz SHASUMS256.txt.asc | sha256sum -c - && \
tar -zxf node-${VERSION}.tar.gz && \
cd node-${VERSION} && \
export GYP_DEFINES="linux_use_gold_flags=0" && \
./configure --prefix=/usr ${CONFIG_FLAGS} && \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
make -j${NPROC} -C out mksnapshot BUILDTYPE=Release && \
paxctl -cm out/Release/mksnapshot && \
make -j${NPROC} && \
make install && \
paxctl -cm /usr/bin/node && \
cd / && \
apk del curl make gcc g++ python linux-headers paxctl gnupg libgcc libstdc++ && \
rm -rf /etc/ssl /node-${VERSION}.tar.gz /SHASUMS256.txt.asc /node-${VERSION} /usr/include \
/usr/share/man /tmp/* /var/cache/apk/* /root/.npm /root/.node-gyp /root/.gnupg
# install yarn
RUN cd /usr/local && wget https://yarnpkg.com/latest.tar.gz -O yarn.tar.gz && tar -zxf yarn.tar.gz && rm yarn.tar.gz && mv dist yarn
ENV PATH="$PATH:/usr/local/yarn/bin"
# switch to unprivileged user
RUN adduser -S nodejs
USER nodejs
RUN mkdir -p /home/nodejs/app
WORKDIR /home/nodejs/app
COPY package.json /home/nodejs/app/
RUN yarn install # --production # https://github.com/yarnpkg/yarn/issues/1015
COPY . /home/nodejs/app
CMD ["yarn", "start"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment