Skip to content

Commit f851f5e

Browse files
Brian Fajardophiltrep
Brian Fajardo
authored andcommitted
Add support for PostgreSQL (#94)
1 parent cb0c279 commit f851f5e

File tree

6 files changed

+92
-0
lines changed

6 files changed

+92
-0
lines changed

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ You can use NoDock for simple projects by using one of the [examples](#Examples)
3232
- [Change Node version](#Node-Version)
3333
- [Change Node project location](#Node-Project-Path)
3434
- [Change MySQL database/user/password](#MySQL-Database-User)
35+
- [Change PostgreSQL database/user/password](#PostgreSQL-Database-User)
3536
- [Change NGINX reverse proxy port](#NGINX-Reverse-Proxy-Port)
3637
- [Change the timezone](#Change-the-timezone)
3738
- [Use RabbitMQ plugins](#Use-RabbitMQ-plugins)
@@ -86,6 +87,7 @@ We provide examples of configurations you might use for a specific stack. Each e
8687
* [Simple Web with Apache](https://github.com/Osedea/nodock/tree/master/_examples/apache) - Node + Apache
8788
* [Simple Web with Nginx](https://github.com/Osedea/nodock/tree/master/_examples/nginx) - Node + NGINX
8889
* [MySQL](https://github.com/Osedea/nodock/tree/master/_examples/mysql) - MySQL + Node + NGINX
90+
* [PostgreSQL](https://github.com/Osedea/nodock/tree/master/_examples/postgresql) - PostgreSQL + Node + NGINX
8991
* [Mongo](https://github.com/Osedea/nodock/tree/master/_examples/mongo) - MongoDB + Node + NGINX
9092
* [RabbitMQ](https://github.com/Osedea/nodock/tree/master/_examples/rabbitmq) - RabbitMQ + Node + NGINX
9193
* [Memcached](https://github.com/Osedea/nodock/tree/master/_examples/memcached) - Memcached + Node + NGINX
@@ -290,6 +292,21 @@ You can specify a `PROJECT_PATH` to change the directory in which `npm` will per
290292
- MYSQL_USER=default_user
291293
- MYSQL_PASSWORD=secret
292294
```
295+
<a name="PostgreSQL-Database-User"></a>
296+
#### Change the PostgreSQL database/user/password
297+
```yaml
298+
# docker-compose.override.yml
299+
[...]
300+
postgresql:
301+
build:
302+
args:
303+
- POSTGRES_DB=default_db
304+
- POSTGRES_USER=default_user
305+
- POSTGRES_PASSWORD=secret
306+
```
307+
308+
309+
293310
<a name="NGINX-Reverse-Proxy-Port"></a>
294311
#### Change the NGINX reverse proxy port
295312
Use port `8080` instead of `8000` to bind your Node server

_examples/postgresql/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## PostgreSQL
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 -r nodock/_examples/postgresql/* .
11+
```
12+
13+
### Usage
14+
15+
```bash
16+
cd nodock/
17+
18+
docker-compose up -d nginx node postgresql
19+
```
20+
21+
Visit `127.0.0.1` to see if Node successfully connected to PostgreSQL!

_examples/postgresql/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const app = require('express')();
2+
const { Client } = require('pg');
3+
4+
app.get('/', function(request, response) {
5+
const client = new Client({
6+
user: 'default_user',
7+
host: 'postgresql',
8+
database: 'default_db',
9+
password: 'secret',
10+
post: 5432,
11+
});
12+
13+
client.connect(function(err, res) {
14+
if (err) {
15+
return response.send('Error occurred while trying to connect to PostgreSQL.');
16+
}
17+
return response.send(`Connected to ${res.host}:${res.port}.`);
18+
});
19+
});
20+
21+
app.listen(8000);

_examples/postgresql/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "postgresql",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"express": "^4.16.2",
8+
"pg": "^7.4.1"
9+
}
10+
}

docker-compose.yml

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ services:
2828
expose:
2929
- "3306"
3030

31+
postgresql:
32+
build:
33+
context: ./postgresql
34+
args:
35+
- POSTGRES_USER=default_user
36+
- POSTGRES_PASSWORD=secret
37+
- POSTGRES_DB=default_db
38+
volumes:
39+
- ./data/postgresql/:/var/lib/postgresql
40+
expose:
41+
- "5432"
42+
3143
mongo:
3244
build: ./mongo
3345
expose:

postgresql/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM postgres:10.2
2+
3+
ARG POSTGRES_USER=default_user
4+
ARG POSTGRES_PASSWORD=secret
5+
ARG POSTGRES_DB=default_db
6+
7+
ENV POSTGRES_USER=$POSTGRES_USER
8+
ENV POSTGRES_PASSWORD=$POSTGRES_PASSWORD
9+
ENV POSTGRES_DB=$POSTGRES_DB
10+
11+
EXPOSE 5432

0 commit comments

Comments
 (0)