Wednesday, December 19, 2018

Docker and PostgresSQL







1 : Create a Postgres docker container 

#Run in container
docker run --name demo -e POSTGRES_PASSWORD=Minhhoa20 -d postgres

#Run with port 5432
docker run -d -p 5432:5432 --name demo -e POSTGRES_PASSWORD=Minhhoa20 postgres

2:Create User and grant privillege

create database demo_db;
create user khanhhuy with encrypted password 'mypass';
grant all privileges on database demo_dbto khanhhuy ;

3: Connect and run some queries
docker exec -it demo psql -U postgres

CREATE DATABASE demo_db1;
\c demo_db1
CREATE TABLE demo_t(something int);
INSERT INTO demo_t (something) VALUES (1);

4: Automate run script
#Copy script to containter
docker cp C:\Users\NVKH\Desktop\postgres\script_demo1.sql demo:/docker-entrypoint-initdb.d/script_demo1.sql
#Running script
docker exec -u postgres demo psql postgres postgres -f docker-entrypoint-initdb.d/script_demo1.sql

khuy

Author & Editor

You may come here to learn not to laugh sorry bout that btw haha

0 nhận xét:

Post a Comment

 
biz.