image.png

  1. Introduction
service:
	postgres:
		image: postgres:13
		environment:
			POSTGRES_USER: airflow
			POSTGRES_PASSWORD: airflow
			POSTGRES_DB: airflow
		volumes:
			- postgres-db-volume:/var/lib/postgresql/data
		healthcheck:
			test: ["CMD", "pg_isready", "-U", "airflow"]
			interval: 5s
			retries: 5
		restart: always
	
docker run -it \\
	-e POSTGRES_USER="root" \\
	-e POSTGRES_PASSWORD="root" \\
	-e POSTGRES_DB="ny_taxi" \\
	-v $(pwd)/ny_taxi_postgres_data=/var/lib/postgresql/data \\
	-p 5432:5432 \\ 
	postgres
	
	
# Giải thích một chút về dòng lệnh command line trên
-it: Chạy một tiến trình command line
-e : Là tag environment tức là các argument môi trường, ví dụ user password hay tên database
-v : là tag volumn tức là ánh xạ dữ liệu storage trong môi trường cô lập docker
ra ngoài ỗ đĩa vật lí storage của ta
-p : là tag port tức là cổng ánh xạ từ môi trường localhost của ta vào trong môi trường docker
  1. Postgres command line for Docker
docker run -it \\
  -e POSTGRES_USER="root" \\
  -e POSTGRES_PASSWORD="root" \\
  -e POSTGRES_DB="ny_taxi" \\
  -v $(pwd)/ny_taxi_postgres_data:/var/lib/postgresql/data \\
  -p 5432:5432 \\
  postgres:13

⚠️ Warning:

If you see that ny_taxi_postgres_data is empty after running the container, try these:

  1. pgcli (postgres command line interface)
pip install pgcli 
# Đây là thư viện tải thư viện để sử dụng interface tương tác với database
#trong postgres sql
pgcli -h localhost -p 5432 -u root -d ny_taxi