Connect to the database itself
If we want to intect with our database we need to interact with postgres database first
1
| docker exec -it postgres psql -Upostgress
|
Create user and database with all privileges entering the container
1
2
3
4
5
6
7
| docker exec -it postgres bash
psql -Upostgress
CREATE USER platops WITH PASSWORD 'platops';
CREATE DATABASE platopsdb;
GRANT ALL PRIVILEGES ON DATABASE platopsdb TO platops;
|
Run psql commands without entering the container
1
| docker exec -it postgres psql -U platops
|
1
| docker exec -it postgres psql -U platops -c "create database platops"
|
1
| docker exec -it postgres psql -Upostgres -a platops -c 'SELECT * FROM posts;'
|
Import or Export with psql CLI
1
| docker exec -t postgres pg_dumpall -c -U platops > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
|
1
| cat dump.sql | docker exec -i postgres psql -U postgres
|