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:
- Web service: node.js server. Using the official node image.
- Database service: MongoDB database. Using the official mongo image.
Yo can find a demo, working here
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
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
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
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
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)
- 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.