Skip to content

Commit

Permalink
Merge pull request #46 from philtrep/mongo-container
Browse files Browse the repository at this point in the history
Mongo container
  • Loading branch information
philtrep authored Oct 14, 2016
2 parents 8e1553d + 70b28d8 commit c891dcb
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ git clone https://github.com/Osedea/nodock.git
## Usage
```
cd nodock
# Simple app
# Run "node" and "nginx"
docker-compose up -d node nginx
# or
# All containers
docker-compose up -d
```

To overwrite the `docker-compose.yml` file you can use a `docker-compose.override.yml`
Expand All @@ -69,6 +66,7 @@ services:
We provide examples of configurations you might use for a specific stack. Each example has it's own README file with instructions.

* [Simple Web](https://github.com/Osedea/nodock/tree/master/_examples/simple-web) - Node + NGINX
* [Mongo](https://github.com/Osedea/nodock/tree/master/_examples/mongo) - MongoDB + Node + NGINX

<a name="Workspace"></a>
## Workspace
Expand Down
21 changes: 21 additions & 0 deletions _examples/mongo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Mongo Service

### Setup

Copy the index file in this folder to the project root:

```bash
cd <project_folder>/

cp nodock/_examples/simple-web/index.js .
cp nodock/_examples/simple-web/package.json .
```

### Usage

```bash
cd nodock/
docker-compose up -d mongo node nginx
```

By going to `127.0.0.1` in your browser you should be seeing a message indicating that `node` as successfully connected to `mongo`.
17 changes: 17 additions & 0 deletions _examples/mongo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var express = require('express');
var app = express();
var MongoClient = require('mongodb').MongoClient;
var MongoUrl = 'mongodb://mongo:27017/nodock';

app.get('/', function(req, res) {
MongoClient.connect(MongoUrl, function(err, db) {
if (err !== null) {
res.send('Could not connect to MongoDB');
} else {
res.send('Connected to MongoDB');
db.close();
}
});
});

app.listen(8000);
15 changes: 15 additions & 0 deletions _examples/mongo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "example-node-mongo-docker",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"express": "^4.14.0",
"mongodb": "^2.2.10"
}
}
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ services:
extra_hosts:
- "dockerhost:10.0.75.1"

mongo:
build: ./mongo
expose:
- "27017"
volumes_from:
- volumes

nginx:
build:
context: ./nginx
Expand Down Expand Up @@ -74,4 +81,5 @@ services:
- ./certbot/letsencrypt/:/var/www/letsencrypt
- ./certbot/certs/:/var/certs
- ./data/mysql:/var/lib/mysql
- ./data/mongo:/var/lib/mongodb
- ./data/logs/nginx/:/var/log/nginx
9 changes: 9 additions & 0 deletions mongo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM mongo:3.3

# Add mongo user
RUN groupadd -r mongo &&\
useradd -r -g mongo mongo

USER mongo

CMD mongod --dbpath=/var/lib/mongodb

0 comments on commit c891dcb

Please sign in to comment.