Я запускаю образ postgres в контейнере Docker и пытаюсь подключиться к нему из другого контейнера с помощью docker-compose.Когда я использую стандартный порт 5432, я могу подключиться нормально, но когда я пытаюсь использовать нестандартный порт вместе с отображением портов, я получаю сообщение об ошибке ECONNREFUSED.
Вот мой составной файл:
networks:
production-net:
driver: bridge
services:
conn-test:
depends_on:
- db
environment:
DB_DIALECT: postgres
DB_HOST: db
DB_NAME: db-name
DB_PASSWORD: pass
DB_PORT: '54321'
DB_USER: user
image: my-image
networks:
production-net: null
db:
environment:
PGDATA: /pgdata
POSTGRES_DB: db-name
POSTGRES_PASSWORD: pass
POSTGRES_USER: user
image: postgres
networks:
production-net: null
ports:
- 54321:5432/tcp
version: '3.0'
А вот вывод, когда я запускаю docker-compose up
Creating network "composer_production-net" with driver "bridge"
Creating composer_db_1 ... done
Creating composer_conn-test_1 ... done
Attaching to composer_db_1, composer_conn-test_1
db_1 | The files belonging to this database system will be owned by user "postgres".
db_1 | This user must also own the server process.
db_1 |
db_1 | The database cluster will be initialized with locale "en_US.utf8".
db_1 | The default database encoding has accordingly been set to "UTF8".
db_1 | The default text search configuration will be set to "english".
db_1 |
db_1 | Data page checksums are disabled.
db_1 |
db_1 | fixing permissions on existing directory /pgdata ... ok
db_1 | creating subdirectories ... ok
db_1 | selecting default max_connections ... 100
db_1 | selecting default shared_buffers ... 128MB
db_1 | selecting dynamic shared memory implementation ... posix
db_1 | creating configuration files ... ok
db_1 | running bootstrap script ... ok
db_1 | performing post-bootstrap initialization ... ok
conn-test_1 | Connecting to database
db_1 | syncing data to disk ...
db_1 | WARNING: enabling "trust" authentication for local connections
db_1 | You can change this by editing pg_hba.conf or using the option -A, or
db_1 | --auth-local and --auth-host, the next time you run initdb.
db_1 | ok
db_1 |
db_1 | Success. You can now start the database server using:
db_1 |
db_1 | pg_ctl -D /pgdata -l logfile start
db_1 |
db_1 | waiting for server to start....2019-02-28 20:52:02.208 UTC [41] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2019-02-28 20:52:02.534 UTC [42] LOG: database system was shut down at 2019-02-28 20:51:58 UTC
db_1 | 2019-02-28 20:52:02.618 UTC [41] LOG: database system is ready to accept connections
db_1 | done
db_1 | server started
db_1 | CREATE DATABASE
db_1 |
db_1 |
db_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1 |
db_1 | waiting for server to shut down....2019-02-28 20:52:04.355 UTC [41] LOG: received fast shutdown request
db_1 | 2019-02-28 20:52:04.432 UTC [41] LOG: aborting any active transactions
db_1 | 2019-02-28 20:52:04.436 UTC [41] LOG: background worker "logical replication launcher" (PID 48) exited with exit code 1
db_1 | 2019-02-28 20:52:04.436 UTC [43] LOG: shutting down
db_1 | 2019-02-28 20:52:04.853 UTC [41] LOG: database system is shut down
db_1 | done
db_1 | server stopped
db_1 |
db_1 | PostgreSQL init process complete; ready for start up.
db_1 |
db_1 | 2019-02-28 20:52:04.941 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2019-02-28 20:52:04.941 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2019-02-28 20:52:05.091 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2019-02-28 20:52:05.342 UTC [59] LOG: database system was shut down at 2019-02-28 20:52:04 UTC
db_1 | 2019-02-28 20:52:05.419 UTC [1] LOG: database system is ready to accept connections
conn-test_1 | Error during start up process
conn-test_1 | connect ECONNREFUSED 172.26.0.2:54321
conn-test_1 | { SequelizeConnectionRefusedError: connect ECONNREFUSED 172.26.0.2:54321
conn-test_1 | at connection.connect.err (/app/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:116:24)
conn-test_1 | at Connection.connectingErrorHandler (/app/node_modules/pg/lib/client.js:140:14)
conn-test_1 | at emitOne (events.js:116:13)
conn-test_1 | at Connection.emit (events.js:211:7)
conn-test_1 | at Socket.reportStreamError (/app/node_modules/pg/lib/connection.js:71:10)
conn-test_1 | at emitOne (events.js:116:13)
conn-test_1 | at Socket.emit (events.js:211:7)
conn-test_1 | at emitErrorNT (internal/streams/destroy.js:66:8)
conn-test_1 | at _combinedTickCallback (internal/process/next_tick.js:139:11)
conn-test_1 | at process._tickCallback (internal/process/next_tick.js:181:9)
conn-test_1 | name: 'SequelizeConnectionRefusedError',
conn-test_1 | parent:
conn-test_1 | { Error: connect ECONNREFUSED 172.26.0.2:54321
conn-test_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
conn-test_1 | errno: 'ECONNREFUSED',
conn-test_1 | code: 'ECONNREFUSED',
conn-test_1 | syscall: 'connect',
conn-test_1 | address: '172.26.0.2',
conn-test_1 | port: 54321 },
conn-test_1 | original:
conn-test_1 | { Error: connect ECONNREFUSED 172.26.0.2:54321
conn-test_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
conn-test_1 | errno: 'ECONNREFUSED',
conn-test_1 | code: 'ECONNREFUSED',
conn-test_1 | syscall: 'connect',
conn-test_1 | address: '172.26.0.2',
conn-test_1 | port: 54321 } }
conn-test_1 | Shutting down the application ...
Я подтвердил, что док-хост разрешает правильный IP-адрес, но не подключается.
Кто-нибудь может указать, что мне здесь не хватает?