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
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 ps_isready for that.
If you want to start that other
service only after the postgres service is up, go with depends_on directive.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.