Using PostgreSQL

docker-compose file example

A simple PostgreSQL service docker-compose file example:

version: '3.1'
services:
  db:
    image: postgres
    container_name: postgres
    restart: on-failure
    tty: true
    environment:
      POSTGRES_PASSWORD: postgres
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - pgdata:/var/lib/postgresql/data
    ports:
      - 5432:5432
  adminer:
    image: adminer
    container_name: pgadmin
    restart: on-failure
    ports:
      - 8080:8080
volumes:
  pgdata:
    name: pgdata

Basic psql commands

List databases

\l

Connect to a database

In other words, the command execution allows to switch to another database.

\c <database_name>