项目作者: mkhuda

项目描述 :
Create PostgreSQL Docker with Multiple Database (Prod, Dev, Test) Grant by postgres User
高级语言: Shell
项目地址: git://github.com/mkhuda/docker-postgresql-multidatabase.git
创建时间: 2018-05-08T16:51:20Z
项目社区:https://github.com/mkhuda/docker-postgresql-multidatabase

开源协议:

下载


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):
    1. $ sudo service postgresql stop
  • Build the Dockerfile and compose it!
  1. $ docker build -t postgres_multi .
  2. $ 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

  1. $ psql -h localhost -p 5432 -U postgres
  2. Password for user postgres:
  3. psql (9.5.5, server 9.5.12)
  4. Type "help" for help.
  5. postgres=# \l
  6. List of databases
  7. Name | Owner | Encoding | Collate | Ctype | Access privileges
  8. -----------+----------+----------+------------+------------+-----------------------
  9. dev_db | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres +
  10. | | | | | postgres=CTc/postgres
  11. postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
  12. prod_db | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres +
  13. | | | | | postgres=CTc/postgres
  14. template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
  15. | | | | | postgres=CTc/postgres
  16. template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
  17. | | | | | postgres=CTc/postgres
  18. test_db | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =Tc/postgres +
  19. | | | | | postgres=CTc/postgres
  20. (6 rows)
  21. postgres=# \q

Use psql -d (database) option

Show database table

  1. $ psql -h localhost -p 5432 -U postgres -d prod_db

Use docker exec, See container ID before by ‘docker ps’ command

  1. $ docker ps
  2. $ docker exec -it [container-id] bash
  3. $ psql -U postgres