File tree Expand file tree Collapse file tree 7 files changed +64
-2
lines changed Expand file tree Collapse file tree 7 files changed +64
-2
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ services:
67
67
We provide examples of configurations you might use for a specific stack. Each example has it's own README file with instructions.
68
68
69
69
* [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
70
71
* [Mongo](https://github.com/Osedea/nodock/tree/master/_examples/mongo) - MongoDB + Node + NGINX
71
72
* [RabbitMQ](https://github.com/Osedea/nodock/tree/master/_examples/rabbitmq) - RabbitMQ + Node + NGINX
72
73
Original file line number Diff line number Diff line change @@ -7,8 +7,8 @@ Copy the index file in this folder to the project root:
7
7
``` bash
8
8
cd < project_folder> /
9
9
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 .
12
12
```
13
13
14
14
### Usage
Original file line number Diff line number Diff line change
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 ` .
Original file line number Diff line number Diff line change
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 ) ;
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ services:
22
22
- MYSQL_DATABASE=default_database
23
23
- MYSQL_USER=default_user
24
24
- MYSQL_PASSWORD=secret
25
+ - MYSQL_ROOT_PASSWORD=root
25
26
volumes_from :
26
27
- volumes
27
28
expose :
Original file line number Diff line number Diff line change @@ -8,10 +8,13 @@ RUN chown -R mysql:root /var/lib/mysql/
8
8
ARG MYSQL_DATABASE
9
9
ARG MYSQL_USER
10
10
ARG MYSQL_PASSWORD
11
+ ARG MYSQL_ROOT_PASSWORD
11
12
12
13
ENV MYSQL_DATABASE=$MYSQL_DATABASE
13
14
ENV MYSQL_USER=$MYSQL_USER
14
15
ENV MYSQL_PASSWORD=$MYSQL_PASSWORD
16
+ ENV MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
17
+
15
18
16
19
RUN sed -i 's/MYSQL_DATABASE/' $MYSQL_DATABASE'/g' /etc/mysql/startup && \
17
20
sed -i 's/MYSQL_USER/' $MYSQL_USER'/g' /etc/mysql/startup && \
You can’t perform that action at this time.
0 commit comments