From e7a5dd7e13d0f9182462d3bd231750604fb248ab Mon Sep 17 00:00:00 2001 From: Parv Jain Date: Thu, 6 Dec 2018 11:38:07 +0530 Subject: [PATCH 1/2] Added Dockerfile, docker-compose.yml, Modifieid database configurations to support dockerization. --- Dockerfile | 25 +++++++++++++++++++++++++ config/database.js | 2 +- docker-compose.yml | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..4628c2e65 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM node:8.11.1 + +# Create app directory +WORKDIR /usr/src/app + +# Install app dependencies +# A wildcard is used to ensure both package.json AND package-lock.json are copied +# where available (npm@5+) +COPY package*.json ./ +# COPY .sequelizerc ./ + +RUN npm install --global nodemon +RUN npm install +# Wil create cassandra keysapce and tables + +# If you are building your code for production +# RUN npm install --only=production + + +# Bundle app source +COPY . . + +EXPOSE 8080 + +CMD [ "nodemon", "server.js" ] diff --git a/config/database.js b/config/database.js index 1f4cfc593..f3c5fbd00 100644 --- a/config/database.js +++ b/config/database.js @@ -1,4 +1,4 @@ module.exports = { remoteUrl : 'mongodb://node:nodeuser@mongo.onmodulus.net:27017/uwO3mypu', - localUrl: 'mongodb://localhost/meanstacktutorials' + localUrl: 'mongodb://todo-mongo:27017/todo-app' }; diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..720b8ab61 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3' + +services: + todo-node: + build: + context: . + ports: + - "8080:8080" + container_name: todo-node + depends_on: + - todo-mongo + + todo-mongo: + image: mongo:latest + restart: always + environment: + MONGO_INITDB_DATABASE: todo-app + container_name: todo-mongo + From c871ee13de8d652735578a40263b698356b3cecf Mon Sep 17 00:00:00 2001 From: Parv Jain Date: Thu, 6 Dec 2018 11:43:05 +0530 Subject: [PATCH 2/2] Modified README.md, added instructions for running app with docker. --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 86e344d81..52d2cecc0 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,18 @@ Node provides the RESTful API. Angular provides the frontend and accesses the AP - [Node and npm](http://nodejs.org) - MongoDB: Make sure you have your own local or remote MongoDB database URI configured in `config/database.js` +# Running the app with Docker + +Install [Docker](https://www.docker.com/) and docker-compose. If you use Windows, click on the icon that will appear on your tray and [enable Shared Drives](https://docs.docker.com/docker-for-windows/#general). + +Then go to the root of this project and: + +```bash +$ docker-compose up +``` + +This will use the docker-compose.yml file inside the infra directory to download and prepare what is needed to run the API. It uses Node.js and MongoDB as the database, so we have 2 Docker containers. + ## Installation 1. Clone the repository: `git clone git@github.com:scotch-io/node-todo`