Skip to content

Commit b702dd8

Browse files
committed
Added mysql example
1 parent a019908 commit b702dd8

File tree

7 files changed

+64
-2
lines changed

7 files changed

+64
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ services:
6767
We provide examples of configurations you might use for a specific stack. Each example has it's own README file with instructions.
6868
6969
* [Simple Web](https://github.com/Osedea/nodock/tree/master/_examples/simple-web) - Node + NGINX
70+
* [MySQL](https://github.com/Osedea/nodock/tree/master/_examples/mysql) - MySQL + Node + NGINX
7071
* [Mongo](https://github.com/Osedea/nodock/tree/master/_examples/mongo) - MongoDB + Node + NGINX
7172
* [RabbitMQ](https://github.com/Osedea/nodock/tree/master/_examples/rabbitmq) - RabbitMQ + Node + NGINX
7273

_examples/mongo/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Copy the index file in this folder to the project root:
77
```bash
88
cd <project_folder>/
99

10-
cp nodock/_examples/simple-web/index.js .
11-
cp nodock/_examples/simple-web/package.json .
10+
cp nodock/_examples/mongo/index.js .
11+
cp nodock/_examples/mongo/package.json .
1212
```
1313

1414
### Usage

_examples/mysql/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## Mysql Service
2+
3+
### Setup
4+
5+
Copy the index file in this folder to the project root:
6+
7+
```bash
8+
cd <project_folder>/
9+
10+
cp nodock/_examples/mysql/index.js .
11+
cp nodock/_examples/mysql/package.json .
12+
```
13+
14+
### Usage
15+
16+
```bash
17+
cd nodock/
18+
19+
docker-compose up -d mysql node nginx
20+
```
21+
22+
By going to `127.0.0.1` in your browser you should be seeing a message indicating that `node` has successfully connected to `mysql`.

_examples/mysql/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var express = require('express');
2+
var app = express();
3+
var mysql = require('mysql');
4+
5+
app.get('/', function(req, res) {
6+
var connection = mysql.createConnection({
7+
host : 'mysql',
8+
user : 'default_user',
9+
password : 'secret'
10+
});
11+
connection.connect(function(err) {
12+
if (err) {
13+
res.send('Could not connect to MySQL ' + err.stack);
14+
} else {
15+
res.send('Connected to MySQL - Thread ' + connection.threadId);
16+
}
17+
});
18+
});
19+
20+
app.listen(8000);

_examples/mysql/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "example-mysql-node-docker",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "MIT",
11+
"dependencies": {
12+
"express": "^4.14.0",
13+
"mysql": "^2.11.1"
14+
}
15+
}

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ services:
2222
- MYSQL_DATABASE=default_database
2323
- MYSQL_USER=default_user
2424
- MYSQL_PASSWORD=secret
25+
- MYSQL_ROOT_PASSWORD=root
2526
volumes_from:
2627
- volumes
2728
expose:

mysql/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ RUN chown -R mysql:root /var/lib/mysql/
88
ARG MYSQL_DATABASE
99
ARG MYSQL_USER
1010
ARG MYSQL_PASSWORD
11+
ARG MYSQL_ROOT_PASSWORD
1112

1213
ENV MYSQL_DATABASE=$MYSQL_DATABASE
1314
ENV MYSQL_USER=$MYSQL_USER
1415
ENV MYSQL_PASSWORD=$MYSQL_PASSWORD
16+
ENV MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
17+
1518

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

0 commit comments

Comments
 (0)