Public Repository

Last pushed: a year ago
Short Description
Docker and runtime.js sample web application
Full Description

Docker and runtime.js sample web application

runtime.js is the library operating system or unikernel implementation based on the JavaScript VM. This repository shows how to run a simple web application with runtime.js in a docker container.

Dockerfile

FROM ubuntu:15.10

# update packages and install curl & qemu
RUN apt-get update && \
apt-get install -y curl qemu && \
# install latest nodejs
curl -sL https://deb.nodesource.com/setup_5.x | bash - && \
apt-get install -y nodejs

RUN [ -f /usr/bin/node ] && echo "node found!" || [ ln -s /usr/bin/nodejs /usr/bin/node ]

# clean cache
RUN rm -rf /var/lib/apt/lists/*

ADD package.json /tmp/package.json

RUN cd /tmp && npm install && \
mkdir -p /home/app && cp -a /tmp/node_modules /home/app/

WORKDIR /home/app

ADD index.js /home/app
ADD package.json /home/app

ADD index.js /tmp/index.js
ADD setup.sh /tmp/setup.sh

EXPOSE 9000

CMD ["npm", "start"]

index.js

Reference: https://github.com/runtimejs/example-web-server

'use strict';

const runtime = require('runtimejs');
const HttpResponse = require('eshttp').HttpResponse;
const HttpServer = require('eshttp').HttpServer;

const server = new HttpServer();
const response = new HttpResponse(200, { server: 'runtimejs' }, 'Hello World!');

server.onrequest = request => {
  request.respondWith(response);
};

server.listen(9000);
console.log('listening to port 9000');

package.json

In a docker container, QEMU runs in "headless node", that's why the option "--nographic" is set.

"name": "runtimejs-web-app",
"version": "1.0.0",
"main": "index.js",
"scripts": {
  "image:create": "runtimeify index.js -o appImg",
  "image:start": "runtime-qemu --nographic ./appImg",
  "start": "npm run image:create && npm run image:start"
},
"license": "MIT",
  "devDependencies": {
  "runtime-tools": "^1.5.2",
  "runtimeify": "^1.0.0"
},
"dependencies": {
  "bluebird": "^2.10.0",
  "runtimejs": "^0.1.25",
  "eshttp": "^0.5.0"
},
"engines": {
"node": "5.6.0"
}

setup.sh

copy node modules into working directory

cp -a /tmp/node_modules /home/app/ | cp /tmp/index.js /home/app/index.js | cp /tmp/package.json /home/app/package.json 

build

docker build -t="mkuegeler/runtimejs" .

run

docker run -p 9000:9000 -it --rm mkuegeler/runtimejs

Now it should be possible to run the server in a web browser

http://localhost:9000
Docker Pull Command
Owner
mkuegeler

Comments (0)