Initialise Postgresql Container with docker-compose


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 following
...
...
..

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

comments powered by Disqus