Skip to content

Commit

Permalink
Merge pull request #58 from philtrep/mysql-example
Browse files Browse the repository at this point in the history
Added mysql example
  • Loading branch information
philtrep authored Oct 19, 2016
2 parents d0d4282 + b702dd8 commit 7aeff8f
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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
* [MySQL](https://github.com/Osedea/nodock/tree/master/_examples/mysql) - MySQL + Node + NGINX
* [Mongo](https://github.com/Osedea/nodock/tree/master/_examples/mongo) - MongoDB + Node + NGINX
* [RabbitMQ](https://github.com/Osedea/nodock/tree/master/_examples/rabbitmq) - RabbitMQ + Node + NGINX
Expand Down
4 changes: 2 additions & 2 deletions _examples/mongo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ 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 .
cp nodock/_examples/mongo/index.js .
cp nodock/_examples/mongo/package.json .
```

### Usage
Expand Down
22 changes: 22 additions & 0 deletions _examples/mysql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Mysql Service

### Setup

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

```bash
cd <project_folder>/

cp nodock/_examples/mysql/index.js .
cp nodock/_examples/mysql/package.json .
```

### Usage

```bash
cd nodock/

docker-compose up -d mysql node nginx
```

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

app.get('/', function(req, res) {
var connection = mysql.createConnection({
host : 'mysql',
user : 'default_user',
password : 'secret'
});
connection.connect(function(err) {
if (err) {
res.send('Could not connect to MySQL ' + err.stack);
} else {
res.send('Connected to MySQL - Thread ' + connection.threadId);
}
});
});

app.listen(8000);
15 changes: 15 additions & 0 deletions _examples/mysql/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "example-mysql-node-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",
"mysql": "^2.11.1"
}
}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:
- MYSQL_DATABASE=default_database
- MYSQL_USER=default_user
- MYSQL_PASSWORD=secret
- MYSQL_ROOT_PASSWORD=root
volumes_from:
- volumes
expose:
Expand Down
3 changes: 3 additions & 0 deletions mysql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ RUN chown -R mysql:root /var/lib/mysql/
ARG MYSQL_DATABASE
ARG MYSQL_USER
ARG MYSQL_PASSWORD
ARG MYSQL_ROOT_PASSWORD

ENV MYSQL_DATABASE=$MYSQL_DATABASE
ENV MYSQL_USER=$MYSQL_USER
ENV MYSQL_PASSWORD=$MYSQL_PASSWORD
ENV MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD


RUN sed -i 's/MYSQL_DATABASE/'$MYSQL_DATABASE'/g' /etc/mysql/startup && \
sed -i 's/MYSQL_USER/'$MYSQL_USER'/g' /etc/mysql/startup && \
Expand Down

0 comments on commit 7aeff8f

Please sign in to comment.