Skip to content

ageapps/docker-node-mongo

Repository files navigation

docker-node-mongo

Basic dockerized server using Node and MongoDB. It shows through a simple example following MVC architecture the basic setup needed to build a server with docker and connect from node Node.js server to MongoDB.

Following the Microservices architecture, the system consists on two services that run in separate containers:

Demo

Yo can find a demo, working here

Using MongoDB replica sets

You just need to use the docker-compose.rps.yml compose file:

$ docker-compose -f docker-compose.rps.yml up
// connect in your browser to <host IP>:8080

Usage with git

Downloading the source code

$ git clone https://github.com/ageapps/docker-node-mongo.git
$ cd docker-node-demo
$ docker-compose up
// connect in your browser to <host IP>:8080

Usage with docker-compose, without source code

Just download docker-compose file to pull all images and build the app.

// download docker-compose file
$ curl https://raw.githubusercontent.com/ageapps/docker-node-mongo/master/docker-hub-compose.yml -o docker-compose.yml
// run application
$ docker-compose up
// connect in your browser to <host IP>:8080

Usage with Docker Hub

No download needed, images will pull automatically.

// run mongo service
$ docker run -v "$(pwd)"/database:/data --name mongo_db -d mongo mongod --smallfiles
// run docker-node-mongo image
$ docker run -d --name node_server --link mongo_db:db -p 8080:3000 ageapps/docker-node-mongo
// connect in your browser to <host IP>:8080

Usage in a cluster with k8s

Try running it in minikube with the following commands

$ minikube start --vm-driver=xhyve
$ kubectl config use-context minikube
$ eval $(minikube docker-env)
$ docker pull mongo
$ kubectl create -f k8s-mongo.yml
$ docker build -t node-mongo:v1 .
$ kubectl create -f k8s-app.yml
// to clean the cluster and get docker local context
$ kubectl delete -f .
$ eval $(minikube docker-env -u) 

Resources

  • Docker: Software containerization platform
  • node.js: Server enviroment.
  • MongoDB: NoSQL database system.
  • mongoose: MongoDB object modeling for node.js.
  • docker-build: Automated build of Docker images.
  • docker-compose: Automated configuration and run of multi-container Docker applications.
  • Kubernetes: open-source system for automating deployment, scaling, and management of containerized applications.

About

Basic dockerized server using Node and MongoDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published