Running Node.js in Docker
This is basically a copy of the Hello World example found here and here with some additional comments.
1. Make the VM running
2. Build the Docker image
Create your Node.js application index.js file:
Create the Docker package.json file:
Create the Dockerfile:
The layout of your directory should be as follows:
Building the image:
Verify if the image exists:
This should print:
3. Running
The option -p
exposes the port 8080
to 49160
. This is essential. Without that, the server is not visible to a client.
Verify, if the process is running:
You should see:
Inspect the image:
You should see a JSON output showing all relevant information:
If the -p
was not given when starting the process, HostPort
would have been null
and the application would not have been visible to clients. Test it:
Now you should see:
Stop and start the process again:
docker ps
doesn't show the process any more. docker ps -a
lists the process as Exited
:
So, start it again:
Test, if the process is running:
Check the logs:
Original post: http://peter-on-java.blogspot.com/2014/06/running-nodejs-in-docker.html
Tags
docker