【发布时间】:2016-04-21 06:44:07
【问题描述】:
我使用 node.js 和 docker 开发应用程序。我的部署过程包括几个步骤:
- 构建 docker-image
- 运行 docker-container
我有 19 秒的时间来运行我的 node_js 容器。但我想至少将时间减少到 1-5 秒。
大部分运行容器时间都需要npm install。
可以加快运行我的 node.js 应用程序的速度吗?
Dockerfile
FROM ubuntu:14.04
MAINTAINER Vovan
# docker build --build-arg NODE_VERSION=any_version .
ARG NODE_VERSION=4.4.2
ARG EXTERNAL_GIT_URI=local_gitlab
ARG EXTERNAL_GIT_PORT=22
# variables
ENV TERM=xterm
# use bash instead of sh
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# essential system updates and soft
RUN apt-get update -qq \
&& apt-get install -yq \
ntp \
build-essential \
curl \
mc \
nano \
git \
&& curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash \
# add nvm as term command
&& . ~/.nvm/nvm.sh \
#
&& nvm install ${NODE_VERSION} \
&& nvm alias default ${NODE_VERSION}
# home directory
RUN useradd -m -d /home/app -s /bin/bash app -u9999
# copy keys in image
ADD for_gitlab /root/.ssh/for_gitlab
ADD config /root/.ssh/config
RUN chmod 600 /root/.ssh/* \
&& ssh-keyscan -p ${EXTERNAL_GIT_PORT} ${EXTERNAL_GIT_URI} > /root/.ssh/known_hosts
# copy script and make it executable
WORKDIR /
RUN mkdir config
ADD starter.sh /config
CMD ["/config/starter.sh"]
RUN chmod +x /config/starter.sh
WORKDIR /home/app
starter.sh
APP_DIR=/home/app/${GIT_REPO_NAME}
GIT_CLONE_URI=git@local_gitlab:${GIT_GROUP}/${GIT_REPO_NAME}.git
cd /home/app
git clone ${GIT_CLONE_URI} --depth 1 --branch ${GIT_REPO_BRANCH}
# permissions
find ${APP_DIR} -type f -exec chmod 644 {} \;
find ${APP_DIR} -type d -exec chmod 755 {} \;
chown -R app:app ${APP_DIR}
#
. ~/.nvm/nvm.sh
nvm use default
cd ${APP_DIR} && npm install
find ${APP_DIR}/node_modules -type f -exec chmod 644 {} \;
find ${APP_DIR}/node_modules -type d -exec chmod 755 {} \;
node ${SCRIPT}
【问题讨论】:
标签: node.js deployment docker dockerfile