【发布时间】:2019-01-07 00:26:07
【问题描述】:
问题是在运行集成测试时,我收到此错误:
error: password authentication failed for user "postgres"
at Connection.parseE (node_modules/pg/lib/connection.js:567:11)
at Connection.parseMessage (node_modules/pg/lib/connection.js:391:17)
无论docker-compose.yml 文件中有什么内容,这种情况都会发生 100%。
我正在使用 knex 进行数据库连接,如下所示:
function getConnectionForDatabase(database) {
return {
host: config.get("database.connection.host"),
user: config.get("database.connection.user"),
password: config.get("database.connection.password"),
database: database
};
}
function getDatabaseConnection(database) {
return knex({
client: config.get("database.client"),
connection: getConnectionForDatabase(database),
debug: config.get("database.debugMode"),
pool: {
min: config.get("database.pool.min"),
max: config.get("database.pool.max")
}
});
}
getDatabaseConnection("postgres");
主机是 127.0.0.1,假设用户名是 postgres,密码是 postgres
docker-compose.yml 包含:
postgres:
image: postgres:9.5.4
command: postgres -D /var/lib/postgresql/data
volumes:
- db-data:/var/lib/postgresql/data
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: 'postgres'
POSTGRES_USER: 'postgres'
我可以使用以下方式手动连接到 postgres 数据库:
docker exec -it <hash> bash
root@<hash>:/# psql -U postgres
我还更新了密码以创建 docker-compose.yml 文件,但它无法连接:
psql -d postgres -c "ALTER USER postgres WITH PASSWORD '<new password>';"
但是,我运行了单元测试...我收到了与上面提到的相同的错误消息!!
我缺少什么来运行这个程序?任何帮助都将不胜感激!
谢谢!
【问题讨论】:
标签: docker authentication docker-compose knex.js postgresql-9.5