1

I have a docker compose file as below. One of the service starts a postgresql server.

version: "3.7"
services:
  postgresql:
    image: "postgres:13-alpine"
    restart: always
    volumes:
      - type: bind
        source: ./DO_NOT_DELETE_postgres_data
        target: /var/lib/postgresql/data
    environment:
      POSTGRES_DB: test
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: abc123
      PGDATA: "/var/lib/postgresql/data/pgdata"
    networks:
      - postgresql_network

   otherservice:
      .... (there are few other services also here)

networks:
  postgresql_network:
    driver: bridge

Now I try to start the docker compose

docker-compose up -d

Now after this I have do some things with the postgresql database from another service otherservice

eg:

docker-compose exec otherservice psql -h postgresql -U postgres -p abc123

How to check the postgresql service is up

Santhosh
  • 9,965
  • 20
  • 103
  • 243

1 Answers1

1

How to check the postgresql service is up

just to check the status you can just simply do docker-compose ps and look at the status.

To see if the service is just just up but is also ready (aka healthy), you can utilize health checks. Use pg_isready for that.

If you want to start that other service only after the postgres service is up, go with depends_on directive.

jabbson
  • 4,390
  • 1
  • 13
  • 23
  • is it pg_ready ? regarding pg_ready - https://stackoverflow.com/a/67363257/2897115. Its not reliable – Santhosh Nov 15 '21 at 05:40