- Call gen_certs.sh and generate CA.
- Call gen_certs.sh and generate server key and certificate.
User rights management is a bit tricky in postgres docker image. So:
-
Comment the blocks
volumes
andcommand
in docker-compose.yml. -
Start image with
docker-compose up
. -
Exit image.
-
Uncomment the blocks from above.
-
Fix permissions of
server.key
andpg_hba.conf
:$ sudo chown root:root pg_hba.conf $ sudo chown root:root certs/server_coffeebuddydb/server.key
Alternatively: Use uid and gid of postgres user which can be determined by:
$ docker-compose exec coffeebuddydb ls --numeric-uid-gid /var/lib/postgresql
-
Restart image.
-
Create dump of sqlite database
sqlite> .output mydump.sql sqlite> .dump sqlite> .exit
-
Generate tables on postgresql
- Call
in __init__.py
flask.current_app.db.create_all()
init_db()
.
- Call
-
Make sql statements compatible to postgres:
- Binary strings have the following format:
E'\\x00000000'
- Binary strings have the following format:
-
Make postgresql docker image accessible from host: Add the following lines to pg_hba.conf:
host all all 172.0.0.0/8 trust
Docker network ips start with
172
(at least on my machine). -
Execute sql dump on host.
$ psql -h localhost -U postgres -d coffeebuddy -f mydump.sql
-
Add hostname of client e.g.
coffeebuddy01
to pg_hba.conf:hostssl coffeebuddy coffeebuddy01 0.0.0.0/0 cert
-
Create role
coffeebuddy01
:$ docker-compose exec coffeebuddydb psql -U postgres -c "create role coffeebuddy01;"
-
Restart postgresql.
-
Generate client certificate and copy root certificate, client key, and certificate to client:
$ scp certs/ca/root.crt certs/client_coffeebuddy01/postgresql.{key,crt} coffeebuddy01:~/.postgresql/