Sign inSign up
node logo

drafa/node

By drafa

•Updated about 11 years ago

Run an Node application which should be on your machine and shared with a volume.

Image
0

333

drafa/node repository overview

⁠IMAGEN DE NODE

This image creates a container to run an application node, which should be on your machine and shared with a volume.

This image is on beta test. Not recomend for production use. Wait a few weeks, I'm working on it.

⁠Structure of project
node_server
    |_ app/
    |    |_ app.js
    |_ node_modules/
    |    |_ <dependencies>
    |_ package.json
    |_ .editorconfig

I recomend use of editorconfig file. See most in editorconfig⁠ website

⁠Preparing the environment
# Generates all directories
mkdir -p $HOME/Docker/node_server/app
cd $HOME/Docker/node_server
touch app/app.js package.json

Now, you need create two files (app.js and package.json). (For example:)

app.js

var express = require("express"),
    app     = express(),
    http    = require("http"),
    server  = http.createServer(app);

app.configure(function () {
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
});

app.get('/', function(req, res) {
  res.send("<h2>Hello world!<h2>Node server running on http://localhost:**PORT**<br/>This is a dummy app. You can deploy your app usign volumes<br/><br/>Example:<br/>****************************************************************<br/>docker run -d -p <host>:<port>:8888 -v $HOME/node/app:/node/app<br/>****************************************************************<br/>Where $HOME/node/app is a directory for your computer and<br/>/node/app is the docker container.");
});

server.listen(**PORT**, function() {
  console.log("Node server running on http://localhost:**PORT**");
});

Rememeber rename your app port to 8888 or to **PORT**. If not change it, app not work. If you desire use other port, donwload Dockerfile and rebuild it.

package.json

{
  "name"         : "node-api-rest-example",
  "version"      : "0.0.1",
  "dependencies" : {
    "express"    : "3.2.6",
    "mongoose"   : "3.6.11",
    "gulp"       : "3.9.0",
    "bower"      : "1.5.3"
  }
}
⁠Install the container

You are prepared for create the container. Execute a docker run with volume for /node/app (If not create a volume, then not working)

docker run --name node -d -p 127.0.0.1:8888:8888 -v $HOME/Docker/node_server:/node/server drafa/node

You can redefine the host 127.0.0.1:: for other.

You can redefine the host port :8888: for other.

You can't redefine the container port ::8888.

You need create a volume for this container and create a app.js and package.json.

And now... you have a node server on your machine.

Remember

  • This container creates a file node_modules on your host volume, this folder have drwxr-xr-x privileges (owner: root). If your user can't execute with root privileges, execute: chmod 777 $HOME/docker/node/app/node_modules, but it not recommended for Production.
  • If you download this proyect from the github then can't edit run.sh script, you need use chmod because its defined with r-x------ privileges. Execute: chmod 700 run.sh for edit the file

Tag summary

Content type

Image

Digest

sha256:133fae43b…

Size

178.1 MB

Last updated

about 11 years ago

docker pull drafa/node