Last active
May 17, 2016 09:43
-
-
Save xizhibei/07a54cab7a47ee1633bf2589005e1571 to your computer and use it in GitHub Desktop.
Dockerfiles for webapp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For your nodejs app | |
# Change your node.js version here | |
FROM node:latest | |
MAINTAINER Xu Zhipei "xuzhipei@gmail.com" | |
RUN groupadd -r app && useradd -r -m -g app app | |
ENV UBUNTU_MIRROR http://ftp.sjtu.edu.cn | |
RUN echo "deb ${UBUNTU_MIRROR}/ubuntu/ trusty main restricted universe multiverse" > /etc/apt/sources.list \ | |
&& echo "deb ${UBUNTU_MIRROR}/ubuntu/ trusty-security main restricted universe multiverse" >> /etc/apt/sources.list \ | |
&& echo "deb ${UBUNTU_MIRROR}/ubuntu/ trusty-updates main restricted universe multiverse" >> /etc/apt/sources.list \ | |
&& echo "deb ${UBUNTU_MIRROR}/ubuntu/ trusty-proposed main restricted universe multiverse" >> /etc/apt/sources.list \ | |
&& echo "deb ${UBUNTU_MIRROR}/ubuntu/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list \ | |
&& echo "deb-src ${UBUNTU_MIRROR}/ubuntu/ trusty main restricted universe multiverse" >> /etc/apt/sources.list \ | |
&& echo "deb-src ${UBUNTU_MIRROR}/ubuntu/ trusty-security main restricted universe multiverse" >> /etc/apt/sources.list \ | |
&& echo "deb-src ${UBUNTU_MIRROR}/ubuntu/ trusty-updates main restricted universe multiverse" >> /etc/apt/sources.list \ | |
&& echo "deb-src ${UBUNTU_MIRROR}/ubuntu/ trusty-proposed main restricted universe multiverse" >> /etc/apt/sources.list \ | |
&& echo "deb-src ${UBUNTU_MIRROR}/ubuntu/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list | |
RUN apt-get update \ | |
&& apt-get install -y --force-yes ca-certificates wget --no-install-recommends \ | |
&& rm -rf /var/lib/apt/lists/* | |
# grab gosu for easy step-down from root | |
ENV GOSU_VERSION 1.7 | |
RUN set -x \ | |
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \ | |
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \ | |
&& export GNUPGHOME="$(mktemp -d)" \ | |
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ | |
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \ | |
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \ | |
&& chmod +x /usr/local/bin/gosu \ | |
&& gosu nobody true | |
# grab tini for signal processing and zombie killing | |
ENV TINI_VERSION v0.9.0 | |
RUN set -x \ | |
&& wget -O /usr/local/bin/tini "https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini" \ | |
&& wget -O /usr/local/bin/tini.asc "https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini.asc" \ | |
&& export GNUPGHOME="$(mktemp -d)" \ | |
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 6380DC428747F6C393FEACA59A84159D7001A4E5 \ | |
&& gpg --batch --verify /usr/local/bin/tini.asc /usr/local/bin/tini \ | |
&& rm -r "$GNUPGHOME" /usr/local/bin/tini.asc \ | |
&& chmod +x /usr/local/bin/tini \ | |
&& tini -h | |
STOPSIGNAL SIGTERM | |
RUN mkdir -p /usr/src/app | |
RUN chown -R app /usr/src/app | |
WORKDIR /usr/src/app | |
ENV NPM_CONFIG_LOGLEVEL http | |
ENV NPM_CONFIG_REGISTRY https://registry.npm.taobao.org | |
ENV PHANTOMJS_CDNURL https://npm.taobao.org/mirrors/phantomjs | |
# for app port | |
ENV PORT 3000 | |
CMD ["gosu", "app", "tini", "node", "app.js"] | |
EXPOSE 3000 | |
# frequently change begins here | |
COPY . /usr/src/app | |
RUN npm install --production | |
RUN npm build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment