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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
---
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
1
2
3
4
5
6
7
8
9
10
11
...
...
..

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

Check with the logs

1
docker logs postgres

comments powered by Disqus