Skip to content

Instantly share code, notes, and snippets.

@jslatts
Last active August 29, 2015 14:05
Show Gist options
  • Save jslatts/f2ffed4e7699e886f60b to your computer and use it in GitHub Desktop.
Save jslatts/f2ffed4e7699e886f60b to your computer and use it in GitHub Desktop.
Dockerfile for node.js app
#!/bin/bash
# Wrapper around shell exec to copy the passed in config value.
# We can move this functionality directly into the app if we deploy.
set -e
if [ ! -z "$CONFIG_TYPE" ]; then
echo "Using $CONFIG_TYPE config"
cp /opt/app/config/${CONFIG_TYPE}.json /opt/app/config/local.json
fi
eval $@
# Dockerfile to run node app
# VERSION 1 - EDITION 2
# Base image used is Ubuntu 14.04 LTS
FROM ubuntu:14.04
MAINTAINER me
# Install wget
RUN apt-get update && apt-get install -y \
wget \
git \
build-essential \
python
# Install Node.js and npm
ENV NODE_VER 0.10.26
RUN wget http://nodejs.org/dist/v$NODE_VER/node-v$NODE_VER-linux-x64.tar.gz
RUN tar xfvz node-v$NODE_VER-linux-x64.tar.gz -C /usr/local
RUN ln -s /usr/local/node-v$NODE_VER-linux-x64/bin/node /usr/local/bin/node
RUN ln -s /usr/local/node-v$NODE_VER-linux-x64/bin/npm /usr/local/bin/npm
RUN mkdir -p /var/log/node
# Install testing tools
RUN npm instal mocha --global
RUN npm instal jshint --global
# Install app dependencies before apps source to avoid rebuilding modules
ADD package.json /tmp/package.json
RUN cd /tmp && npm install && npm prune
RUN mkdir -p /opt/app && cp -a /tmp/node_modules /opt/app
# Bundle app source
ADD . /opt/app
EXPOSE 8080
# Set entrypoint to handle config switching
ADD docker-entrypoint.sh /entrypoint.sh
RUN chmod u+x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["node", "/opt/app/server.js"]
docker run -e CONFIG_TYPE=docker image/name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment