Just use Docker-Compose
# docker-compose.yml
version: "3"
name: <main_container_name> # Project name container name (otherwise it will use the folder name)
services:
db:
container_name: <db_container_name> # Subcontainer name: <main_container_name>_db_1
image: postgis/postgis
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password123
# Creates a new "Database" of this name only
# if no initial databases exist. It only runs the first time.
POSTGRES_DB: <db_name> # Your connection string will be: postgresql://postgres:[email protected]:5432/<db_name>
volumes:
- ./data:/var/lib/postgresql/data
ports:
- "5432:5432"docker exec -ti <db_container_name> - Prefix your commands with this if db is in Docker.
psql -U postgres - Login
\l - List databases
\c - Connect to database
\dn - List schemas inside database
\dt - List tables inside public schemas
\dt schema1.* - List tables inside a particular schema.
For example: 'schema1'.
\d - Display schema of a table
\d+ - Display schema of a table + more info.
create database <db_name>; - create a database# Describe A Table
SELECT * FROM information_schema.columns where table_name = '<table name>';Note
Work in Progress