NodeJS App and Docker
1 Dockerfile to Install the Env and App
#Run a Simple REST API based on playframework
#Prepre the OS
FROM centos:7
MAINTAINER Carl Luo <
[email protected]>
ENV DEBIAN_FRONTEND noninteractive
ENV HTTP_PORT 8004
#Install nodeJS and foreverJS
RUN yum groupinstall -y "Development Tools"
RUN mkdir /tool/
WORKDIR /tool/
ADD install/node-v4.2.3.tar.gz /tool/
WORKDIR /tool/node-v4.2.3
RUN ./configure
RUN make
RUN make install
RUN npm install -g forever
#Install the Application
RUN mkdir -p /share/email-scan
WORKDIR /share/email-scan
ADD /dist/email-scan-1.0.tar.gz /share/email-scan
#Start the Application
EXPOSE 8004
RUN mkdir -p /app/
ADD start.sh /app/
WORKDIR /app
CMD [ "./start.sh" ]
2 Start Command start.sh
#!/bin/sh -ex
cd /share/email-scan
PORT=8004 forever start --minUptime 10000 --spinSleepTime 10000 -a -l forever.log -o ./logs/out.log -e ./logs/err.log app.js
tail -f /dev/null
The last command tail -f /dev/null is important, that will keep the container running.
3 Makefile for Run/Debug/Build
IMAGE=sillycat/email-scan
TAG=1.0
NAME=email-scan
REPOSITORY=registry.sillycat.com
prepare:
wget https://nodejs.org/dist/v4.2.3/node-v4.2.3.tar.gz -P install/
push-local:
docker push $(REPOSITORY)/$(IMAGE):$(TAG)
app-build:
gulp dist
docker-context:
build: docker-context
docker build -t $(REPOSITORY)/$(IMAGE):$(TAG) .
run-stage:
docker run -d -p 8004:8004 -e RUNNING_ENV=stage --name $(NAME) $(REPOSITORY)/$(IMAGE):$(TAG)
debug:
docker run -ti -p 8004:8004 --name $(NAME) $(REPOSITORY)/$(IMAGE):$(TAG) /bin/bash
clean:
docker stop ${NAME}
docker rm ${NAME}
logs:
docker logs ${NAME}
publish:
docker push ${IMAGE}
References:
http://sillycat.iteye.com/blog/2258021