0

I am trying my hands on deploying a sample node js application to docker.

I am following the tutorial from http://oskarhane.com/create-a-nodejs-docker-io-image/.

In the tutorial , there is step 4: where the author asks to modify the app.js with the code and place in /app/www/app.js But my question is when I do winscp , I could not find the folder /www in /var . I am literally stuck at this place .

Can anybody tell me how to modify the js file app.js with the server code ? Or any simpler step by step appraoch is there for deploying any apps on ubuntu 12.04 docker please let me know.

user1907849
  • 960
  • 4
  • 19
  • 42

2 Answers2

4

The author creates /var/www in step 2:

mkdir /var/www && echo 'console.log("Hello from Node.js");' > /var/www/app.js

He commits it to an image in step 3. So the image you get after step 3 should container /var/www:

docker commit 0a7e9dd8dbdd NodeBase

So the image NodeBase will contain a folder /var/www. If not, you made a mistake in step 2 or 3.

However, I think this is a strange tutorial. Building the container in a interactive shell isn't very advisable. Instead I would use a Dockerfile to build your image. Do you know how to install Node.js on (let's say) Ubuntu? If you do, you can do the very same in a Dockerfile:

FROM ubuntu
RUN apt-get -y install nodejs
ADD /your-app/ /var/www/your-app
CMD run-node-here

Then build the image by docker build -t yourImage . and run it.

Node.js is very popular, so you have good luck to find an already prepared Node.js image. You could go to https://index.docker.io and just search for a suitable Node.js image. The very first one you will find will be https://index.docker.io/u/dockerfile/nodejs/. You can just use this image and mount your own application to it:

docker pull dockerfile/nodejs
docker run -it -v /your/node/app:/data:rw --rm dockerfile/nodejs node 

Note that I have no experience with Node.js, just with Docker. So I haven't tested this stuff, I just give you a general advise how to do it. If you don't want to bother with installing Node.js, search an image where you can mount your app and start Node.js (maybe the one mentioned above). Otherwise, write your own Dockerfile and install Node.js just as you would do it on Linux.

Thomas Uhrig
  • 30,811
  • 12
  • 60
  • 80
  • Also , One more thing everywhere in tutorials I see building a dockerfile and use it... but nodbody has given clear instructions on how to run dockerfile?is dockerfile a text file ?Or how to create a dockerfile ...Please dont get me wrong ,but its very difficult for a newbie like to get what dockerfile is. – user1907849 May 30 '14 at 08:25
  • A Dockerfile is a normal text file, which is just named `Dockerfile` without any file extension. You find the reference at http://docs.docker.io/reference/builder/ and a good beginner tutorial at https://www.docker.io/learn/dockerfile/. Generally, a Dockerfile defines a set of commands (start from ubuntu, install this, copy that) which build an image. – Thomas Uhrig May 30 '14 at 09:30
0

You can use vi editor if nano doesn't work in some versions of Ubuntu

user1400915
  • 1,933
  • 6
  • 29
  • 55