lundi 1 décembre 2014

Node Docker Container - Pulls from Git Repo for Node App Source Upon Running


Vote count:

0




I am trying to create a docker image that is generic and can be used with all my Node applications. My current docker image and logic pulls the source for the app from the specified Git repo received as a command line arg when running the docker image. Here is the code for the docker file and entrypoint logic:


Dockerfile:



# Generic Docker Image for Running Node app from Git Repository
FROM node:0.10.33-slim
ENV NODE_ENV production

# Add script to pull Node app from Git and run the app
COPY docker-node-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

EXPOSE 8080
CMD ["/bin/echo", "Usage: docker run -p 49160:8080 -d <image name>", \
"node-server", "[Git Repo URL with Username:Password]", \
"[Optional Git Commit Id]"]


Entrypoint script:



#!/bin/bash
set -e
# Run the command passed in if it isn't to start a node app
if [ "$1" != 'node-server' ]; then
exec "$@"
fi
# Logic for pulling the node app and starting it
cd /usr/src
# try to remove the repo if it already exists
rm -rf node-app; true
echo "Pulling Node app's source from $2"
git clone $2 node-app
cd node-app
# Check if we should be running a specific commit from the git repo
if [ ! -z "$3" ]; then
echo "Changing to commit $3"
git checkout $3
fi
npm install
echo "Starting the app"
exec node .


This seems to be working fine when doing a simple docker run command. However I am concerned I may not be fully understanding docker and it may cause issues with my setup. Can you help me understand if there are issues with this approach and understand the following:


1) Is there a way for echo's to show up in the terminal where the docker run command is issued. It appears echo's only show here if the -d option isn't used. I can do docker logs to see these echos but I wanted to know if there was a way for them to show directly in the terminal issuing the run command?


2) I know Docker recommends using the exec command to not have your process killed via SIGKILL when the container is stopped and it times out? Are there any concerns about the git clone command and npm install command running when the container is stopped as I am not using exec? Is there a way to fix this in my entrypoint script?


3) How does docker start differ from docker run? If my docker run requires command line args for starting the container properly, do I also have to pass these in when issuing a start command? Does Docker re-run the entry point script when a start command is issued? Is there a way to optimize my script so that it doesn't re-pull the node source from the git repro and the required dependencies after the start command?


4) Is there a reason I need to chmod +x on my entrypoint script? It didn't appear Redis was doing this in their dockerfile (http://ift.tt/11JTan3) for their entrypoint script.



asked 1 min ago







Node Docker Container - Pulls from Git Repo for Node App Source Upon Running

Aucun commentaire:

Enregistrer un commentaire