Initialise Postgresql Container with docker-compose

Initialise Postgresql Container with docker-compose

Prerequisite

  1. Install Docker
  2. install docker-compose
  • Create a docker-compose.yml with the following
---
version: '3'
services:
  postgress-postgresql:
    image: postgres:11.4
    container_name: postgres
    volumes:
        - data-postgresql:/var/lib/postgresql/data/
    environment:
      - POSTGRES_USER=postgress
      - POSTGRES_PASSWORD=
    ports: ['5432:5432']

volumes:
  data-postgresql:
  • Set the custom volume for the postgres persistency, update the docker volume of the above yml with the folowing
...
...
..

volumes:
  data-postgresql:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: /path/of/db/postgres/data/  
  • Run
docker-compose up -d

Check with the logs

docker logs postgres
# database # postgresql Initialise Postgresql Container with docker-compose Initialise Postgresql Container with init SQL script Basic command to run with Postgress Container