/docker-boilerplate

Dockerfile Boilerplate for nginx, redis, mongodb, neo4j, and node.js

Primary LanguageJavaScript

BUILD

For every desired module, browse to its folder (e.g: node) and type

	docker build -t <name> .

Run docker container:

docker run -d --name redis -p 6379:6379 redis
docker run -d --name mongodb -p 27017:27017 -v /opt/mongodb:/data/db mongodb
docker run -d --name neo4j --privileged -p 7474:7474 -p 1337:1337 -v /home/core:/var/lib/neo4j/data neo4j
docker run -d --name node -p 8080:8080 --link redis:redis --link mongodb:mongodb node
docker run -d --name nginx -p 80:80 --link node:node nginx

HOW-TO

  1. Add bridged adapter on boot2docker on Windows

     	Shut down boot2docker
     	Open the VirtualBox dashboard
     	Edit the Settings
     	Go to Network
     	Enable Adapter 3
     	Set to Bridged Adapter
     	Save, exit
     	Restart boot2docker
     	boot2docker ssh 
     	run ifconfig and find the 3rd nic (eth2), write down the inet address
    
  2. Access files in container

     	# find ID of your running container:
     	docker ps
     	
     	# create image (snapshot) from container filesystem
     	docker commit 12345678904b5 mysnapshot
     	
     	# explore this filesystem using bash (for example)
     	docker run -t -i mysnapshot /bin/bash
    
  3. How to pointing node.js app to redis/mongodb server

     	Configure node.js to look for environment variable 
     	
     	-- Example environment variables on node container ---
     	MONGODB_PORT=tcp://{your-ip}:27017
     	MONGODB_PORT_27017_TCP=tcp://{your-ip}:27017
     	MONGODB_PORT_27017_TCP_ADDR={your-ip}
     	MONGODB_PORT_27017_TCP_PORT=27017
     	MONGODB_PORT_27017_TCP_PROTO=tcp
     	MONGODB_NAME=/node/mongodb
     	REDIS_PORT=tcp://{your-ip}:6379
     	REDIS_PORT_6379_TCP=tcp://{your-ip}:6379
     	REDIS_PORT_6379_TCP_ADDR={your-ip}
     	REDIS_PORT_6379_TCP_PORT=6379
     	REDIS_PORT_6379_TCP_PROTO=tcp
     	REDIS_NAME=/node/redis
     	-----------------
    
  4. How to install docker UI

     	docker run -d -p 9000:9000 --privileged -v /var/run/docker.sock:/var/run/docker.sock dockerui/dockerui
    
  5. How to install CoreOS on Windows

     	1. Download vagrant for Windows, http://www.vagrantup.com/downloads.html
     	2. In vagrant folder, type:
     				vagrant init yungsang/coreos
     				vagrant up
     	3. Make sure ssh.exe is in your PATH variable (download GIT if don't have SSH around)			
     	4. Connect to CoreOS:
     				vagrant ssh			
     	5. Optional, create user in CoreOS for easy file upload (vis WinSCP)
     				sudo useradd -p password -U -m username -G sudo		
    

CREDITS

http://anandmanisankar.com/posts/docker-container-nginx-node-redis-example/