以前一切正常/工作正常,但突然不起作用,这些 docker 使用库生成github.com/ory/dockertest
,端口 49157/tcp 转发到 5432:
docker ps
CONTAINER ID IMAGE COMMAND CREATED
0fe02164c0d3 postgres:11.4-alpine "docker-entrypoint.s…" 8 minutes ago
STATUS PORTS NAMES
Up 8 minutes 0.0.0.0:49157->5432/tcp, :::49157->5432/tcp laughing_gould
docker 内的 netstat 没问题:
docker exec -it 0fe02164c0d3 bash
bash-5.0# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN -
tcp 0 0 :::5432 :::* LISTEN -
bash-5.0# psql -U foo -h 127.0.0.1 -p 5432 foodb
psql (11.4)
Type "help" for help.
foodb=#
日志看起来不错:
docker logs
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /pgtmpfs ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
sh: locale: not found
2021-10-04 20:30:27.355 UTC [28] WARNING: no usable system locales were found
performing post-bootstrap initialization ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /pgtmpfs -l logfile start
waiting for server to start....2021-10-04 20:30:42.460 UTC [32] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-10-04 20:30:42.599 UTC [33] LOG: database system was shut down at 2021-10-04 20:30:27 UTC
2021-10-04 20:30:42.641 UTC [32] LOG: database system is ready to accept connections
done
server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
waiting for server to shut down....2021-10-04 20:30:47.348 UTC [32] LOG: received fast shutdown request
2021-10-04 20:30:47.406 UTC [32] LOG: aborting any active transactions
2021-10-04 20:30:47.406 UTC [32] LOG: background worker "logical replication launcher" (PID 39) exited with exit code 1
2021-10-04 20:30:47.407 UTC [34] LOG: shutting down
2021-10-04 20:30:47.533 UTC [32] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
2021-10-04 20:30:47.562 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-10-04 20:30:47.562 UTC [1] LOG: listening on IPv6 address "::", port 5432
2021-10-04 20:30:47.593 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-10-04 20:30:47.676 UTC [43] LOG: database system was shut down at 2021-10-04 20:30:47 UTC
2021-10-04 20:30:47.684 UTC [1] LOG: database system is ready to accept connections
来自主机的 netstat 也可以:
netstat -antp | grep 49157
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:49157 0.0.0.0:* LISTEN -
tcp6 0 0 :::49157 :::* LISTEN -
telnet 到该端口也可以:
telnet localhost 49157
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
^]
但是当尝试从主机连接到该docker时,总是超时,这可能是什么原因?
psql -h 127.0.0.1 -U foo -p 49157 foodb
psql: error: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
更新对于来自主机的 nginx 也不起作用,但在 docker 内部时没问题。