Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mkhuda/docker-postgresql-multidatabase
Create PostgreSQL Docker with Multiple Database (Prod, Dev, Test) Grant by postgres User
https://github.com/mkhuda/docker-postgresql-multidatabase
docker docker-compose dockerfile postgresql postgresql-database
Last synced: 17 days ago
JSON representation
Create PostgreSQL Docker with Multiple Database (Prod, Dev, Test) Grant by postgres User
- Host: GitHub
- URL: https://github.com/mkhuda/docker-postgresql-multidatabase
- Owner: mkhuda
- Created: 2018-05-08T16:51:20.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-11T08:03:58.000Z (over 6 years ago)
- Last Synced: 2025-01-09T13:57:17.683Z (18 days ago)
- Topics: docker, docker-compose, dockerfile, postgresql, postgresql-database
- Language: Shell
- Size: 3.91 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Docker Multiple Database for PostgreSQL
Based on Postgresql 9.5 (Can be used to any versions) with Persistent Data.
## Usage
- Stop your current postgresql default system (If you have installed postgresql on PORT 5432):
```
$ sudo service postgresql stop
```
- Build the Dockerfile and compose it!```
$ docker build -t postgres_multi .
$ docker-compose up -d
```It will create 3 database for you `prod_db`, `dev_db`, and `test_db` within `postgres` User.
In order to test `psql` command, you can stop postgresql system by `sudo service postgresql stop` that uses PORT 5432.
And then:
> Show created database```
$ psql -h localhost -p 5432 -U postgres
Password for user postgres:
psql (9.5.5, server 9.5.12)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
dev_db | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres +
| | | | | postgres=CTc/postgres
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
prod_db | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres +
| | | | | postgres=CTc/postgres
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
test_db | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres +
| | | | | postgres=CTc/postgres
(6 rows)
postgres=# \q
```> Use psql -d (database) option
> Show database table
```
$ psql -h localhost -p 5432 -U postgres -d prod_db
```> Use docker exec, See container ID before by 'docker ps' command
```
$ docker ps
$ docker exec -it [container-id] bash
$ psql -U postgres
```