Docker Community Forums

Share and learn in the Docker community.

How To Build Docker Image With NodeJS App


(Billpaxton) #1

Hi guys. I’m trying to basically build my first Docker image which I believe I have successfully accomplished because it gets through all steps without any issues (after much trial and error though).

The problem I’m experiencing though is the fact that within my Docker image, I’m running a NodeJS application. Those of you familiar with NodeJS applications will know that whenever a NodeJS app is started, usually it takes control of the terminal and just sits there saying something along the lines of “Application X is running”. An example of this would be the Ghost blogging NodeJS application.

So what I’m running into is when I’m trying to initially build my image, it never completely builds because it gets to the part where the NodeJS app starts and hangs there saying the app is running. I feel like I’m going about this the wrong way and would just like some guidance into how I can get this image successfully built.

Thank you in advance!


(Sven Dowideit) #2

Heya,

sounds like you have it almost right :smile:

you don’t want to start your application as a RUN statement in the Dockerfile, you want to leave that step for docker run - which means either in the Dockerfile ENTRYPOINT, or the Dockerfile CMD

The Docker users guide is pretty good with giving you all the basics: http://docs.docker.com/userguide/

and then the examples, like http://docs.docker.com/examples/nodejs_web_app/ can hopefully finish it off :slight_smile:


(Sven Dowideit) #3

mmm, reading that last one, we need to update it to use the node image. but the principles still apply


(Billpaxton) #4

Hi sven! Thanks for your feedback. I actually just ended up using ADD and creating a bash script to perform the “post-install” functions. I hope that’s not considered the lazy way! :stuck_out_tongue: