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/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` 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 +