我正在尝试使用 访问 PostgreSQL 的 shell ( psql
) docker-compose
,但我遇到了一些困难......这是我的docker-compose
文件:
main:
build: .
volumes:
- .:/code
links:
- postgresdb
environment:
- DEBUG=true
postgresdb:
build: utils/sql/
ports:
- "5432"
environment:
- DEBUG=true
我试图psql
通过运行main
以及服务来访问postgresdb
docker-compose run postgresdb psql -h postgresdb -U docker mydatabase
但我得到的只是psql: could not translate host name "postgresdb" to address: Name or service not known
......我不明白,因为我postgresdb
在数据库配置文件中用作主机,例如:
DB_ACCESS = {
'drivername': 'postgres',
# Name of docker-compose service
'host': 'postgresdb',
'port': '5432',
'username': 'docker',
'password': '',
'database': 'mydatabase'
}