如何使用Netcat检查postgresql docker容器是否已启动

问题描述 投票:0回答:1

我想看看使用Netcat实用程序是否已准备好带有PostgreSQL的Docker容器。

我的entrypoint.sh脚本似乎无法发现数据库并开始运行。当我登录docker并以详细模式运行NC时,我得到

DNS fwd/rev mismatch: db != telegram_messages_db_1.telegram_messages_default

我在做什么错?

我的设置

entrypoint.sh

echo "Waiting for postgres..."

while ! nc -z db 5432; do
  sleep 0.1
done

echo "PostgreSQL started"

docker-compose.yaml

version: '3.7'

services:

  messages:
    build:
      context: .
      dockerfile: Dockerfile
    entrypoint: ['/usr/src/app/entrypoint.sh']  # new
    volumes:
      - .:/usr/src/app
    ports:
      - 5001:5000
    environment:
      .....
    depends_on:
      - db

  db:
    build:
      context: ./backend/db
      dockerfile: Dockerfile
    expose:
      - 5432
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres      

docker-compose输出

Attaching to telegram_messages_db_1, telegram_messages_messages_1
messages_1  | Waiting for postgres...
db_1        | 
db_1        | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1        | 
db_1        | 2020-03-29 23:55:22.103 UTC [1] LOG:  starting PostgreSQL 12.2 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.2.0) 9.2.0, 64-bit
db_1        | 2020-03-29 23:55:22.103 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1        | 2020-03-29 23:55:22.104 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1        | 2020-03-29 23:55:22.115 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1        | 2020-03-29 23:55:22.170 UTC [20] LOG:  database system was shut down at 2020-03-29 23:46:56 UTC
db_1        | 2020-03-29 23:55:22.190 UTC [1] LOG:  database system is ready to accept connections

也...

如果我运行nc -z -v telegram_messages_db_1.telegram_messages_default 5432我得到一个不错的答复:

telegram_messages_db_1.telegram_messages_default [172.19.0.2] 5432 (postgresql) open
postgresql docker docker-compose netcat
1个回答
0
投票

是的...删除所有容器,重新启动并从头开始构建即可解决此问题。

我将其留给后代。

¯_(ツ)_ /¯

© www.soinside.com 2019 - 2024. All rights reserved.