-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from philtrep/mongo-container
Mongo container
- Loading branch information
Showing
6 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |