Skip to content

Commit 15065c4

Browse files
author
Daniel Gasienica
committed
Initial commit
0 parents  commit 15065c4

7 files changed

+204
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
3+
# Node.js
4+
/node_modules
5+
6+
# Vagrant
7+
.vagrant

Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# VERSION 0.2
2+
# DOCKER-VERSION 0.3.4
3+
# To build:
4+
# 1. Install docker (http://docker.io)
5+
# 2. Checkout source: [email protected]:gasi/docker-node-hello.git
6+
# 3. Build container: docker build .
7+
8+
FROM centos:6.4
9+
10+
# Enable EPEL for Node.js
11+
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
12+
# Install Node.js and npm
13+
RUN yum install -y npm-1.2.17-5.el6
14+
15+
# App
16+
ADD . /src
17+
EXPOSE 8080
18+
CMD ["node", "/src/index.js"]

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
install:
2+
npm install
3+
4+
build:
5+
docker build -t gasi/centos-node-hello .
6+
7+
run:
8+
node index.js
9+
10+
run-container:
11+
docker run -d gasi/centos-node-hello
12+
13+
test:
14+
curl localhost
15+
16+
clean:
17+
rm -rf node_modules
18+
19+
20+
.PHONY: install build run test clean

README.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Node.js Hello World
2+
3+
Node.js Hello World on CentOS using [docker][].
4+
5+
## Prerequisites
6+
7+
- [Node.js & npm][node-js-download]
8+
9+
## Getting Started
10+
11+
- Start Ubuntu virtual machine using Vagrant (required to run docker):
12+
13+
vagrant up
14+
15+
- SSH into virtual machine:
16+
17+
vagrant ssh
18+
19+
- Install dependencies:
20+
21+
cd /vagrant
22+
make install
23+
24+
- Build docker image:
25+
26+
make build
27+
# docker build -t gasi/centos-node-hello .
28+
29+
30+
- Run app:
31+
32+
make run-container
33+
# docker run -d gasi/centos-node-hello
34+
35+
- Install `curl`:
36+
37+
sudo apt-get install curl
38+
39+
- Get mapped port (last column) using, e.g. 49160:
40+
41+
docker ps
42+
43+
> # Example
44+
> ID IMAGE COMMAND CREATED STATUS PORTS
45+
> ecce33b30ebf gasi/centos-node-hello:latest node /src/index.js 10 seconds ago Up 9 seconds 49160->8080
46+
47+
- Test app using the port in previous step, e.g. 49160:
48+
49+
curl localhost:<port>
50+
51+
# Example
52+
# curl localhost:49163
53+
54+
It should print `Hello World` to the console.
55+
56+
## Acknowledgements
57+
58+
Many thanks to @shykes and @unclejack for their support on IRC as well as the
59+
@dotCloud team for docker.
60+
61+
62+
[node-js-download]: http://nodejs.org/download/
63+
[docker]: http://docker.io

Vagrantfile

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
BOX_NAME = ENV['BOX_NAME'] || "ubuntu"
5+
BOX_URI = ENV['BOX_URI'] || "http://files.vagrantup.com/precise64.box"
6+
AWS_REGION = ENV['AWS_REGION'] || "us-east-1"
7+
AWS_AMI = ENV['AWS_AMI'] || "ami-d0f89fb9"
8+
9+
Vagrant::Config.run do |config|
10+
# Setup virtual machine box. This VM configuration code is always executed.
11+
config.vm.box = BOX_NAME
12+
config.vm.box_url = BOX_URI
13+
14+
# Provision docker and new kernel if deployment was not done
15+
if Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/default/*/id").empty?
16+
# Add lxc-docker package
17+
pkg_cmd = "apt-get update -qq; apt-get install -q -y python-software-properties; " \
18+
"add-apt-repository -y ppa:dotcloud/lxc-docker; apt-get update -qq; " \
19+
"apt-get install -q -y lxc-docker; "
20+
# Add X.org Ubuntu backported 3.8 kernel
21+
pkg_cmd << "add-apt-repository -y ppa:ubuntu-x-swat/r-lts-backport; " \
22+
"apt-get update -qq; apt-get install -q -y linux-image-3.8.0-19-generic; "
23+
# Add guest additions if local vbox VM
24+
is_vbox = true
25+
ARGV.each do |arg| is_vbox &&= !arg.downcase.start_with?("--provider") end
26+
if is_vbox
27+
pkg_cmd << "apt-get install -q -y linux-headers-3.8.0-19-generic dkms; " \
28+
"echo 'Downloading VBox Guest Additions...'; " \
29+
"wget -q http://dlc.sun.com.edgesuite.net/virtualbox/4.2.12/VBoxGuestAdditions_4.2.12.iso; "
30+
# Prepare the VM to add guest additions after reboot
31+
pkg_cmd << "echo -e 'mount -o loop,ro /home/vagrant/VBoxGuestAdditions_4.2.12.iso /mnt\n" \
32+
"echo yes | /mnt/VBoxLinuxAdditions.run\numount /mnt\n" \
33+
"rm /root/guest_additions.sh; ' > /root/guest_additions.sh; " \
34+
"chmod 700 /root/guest_additions.sh; " \
35+
"sed -i -E 's#^exit 0#[ -x /root/guest_additions.sh ] \\&\\& /root/guest_additions.sh#' /etc/rc.local; " \
36+
"echo 'Installation of VBox Guest Additions is proceeding in the background.'; " \
37+
"echo '\"vagrant reload\" can be used in about 2 minutes to activate the new guest additions.'; "
38+
end
39+
# Activate new kernel
40+
pkg_cmd << "shutdown -r +1; "
41+
config.vm.provision :shell, :inline => pkg_cmd
42+
end
43+
end
44+
45+
46+
# Providers were added on Vagrant >= 1.1.0
47+
Vagrant::VERSION >= "1.1.0" and Vagrant.configure("2") do |config|
48+
config.vm.provider :aws do |aws, override|
49+
aws.access_key_id = ENV["AWS_ACCESS_KEY_ID"]
50+
aws.secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
51+
aws.keypair_name = ENV["AWS_KEYPAIR_NAME"]
52+
override.ssh.private_key_path = ENV["AWS_SSH_PRIVKEY"]
53+
override.ssh.username = "ubuntu"
54+
aws.region = AWS_REGION
55+
aws.ami = AWS_AMI
56+
aws.instance_type = "t1.micro"
57+
end
58+
59+
config.vm.provider :rackspace do |rs|
60+
config.ssh.private_key_path = ENV["RS_PRIVATE_KEY"]
61+
rs.username = ENV["RS_USERNAME"]
62+
rs.api_key = ENV["RS_API_KEY"]
63+
rs.public_key_path = ENV["RS_PUBLIC_KEY"]
64+
rs.flavor = /512MB/
65+
rs.image = /Ubuntu/
66+
end
67+
68+
config.vm.provider :virtualbox do |vb|
69+
config.vm.box = BOX_NAME
70+
config.vm.box_url = BOX_URI
71+
end
72+
end

index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var express = require('express');
2+
3+
// Constants
4+
var DEFAULT_PORT = 8080;
5+
var PORT = process.env.PORT || DEFAULT_PORT;
6+
7+
// App
8+
var app = express();
9+
app.get('/', function (req, res) {
10+
res.send('Hello World\n');
11+
});
12+
13+
app.listen(PORT)
14+
console.log('Running on http://localhost:' + PORT);

package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "docker-centos-hello-world",
3+
"private": true,
4+
"version": "0.0.1",
5+
"description": "Node.js Hello World app on CentOS using docker",
6+
"author": "Daniel Gasienica <[email protected]>",
7+
"dependencies": {
8+
"express": "3.2.4"
9+
}
10+
}

0 commit comments

Comments
 (0)