Hi
I am newbie in Docker world. I have a problem: my Yii application throw database exceptin. Yes I have read about it on the google. But I think my configuration is fine.
This is the error:
SQLSTATE[08006] [7] could not translate host name "postgres" to address: Name or service not known
So I have the following docker-compose.yml file:
app:
image: ubuntu:16.04
volumes:
- .:/var/www/html
command: "true"
nginx:
build: ./docker/nginx/
ports:
- 80:80
links:
- php
volumes_from:
- app
volumes:
- ./docker/nginx/conf.d:/etc/nginx/conf.d
php:
build: ./docker/php/
expose:
- 9000
links:
- postgres
- redis
volumes_from:
- app
postgres:
image: postgres:latest
volumes:
- /var/lib/postgres
environment:
POSTGRES_DB: project
POSTGRES_USER: project
POSTGRES_PASSWORD: project
command: "true"
redis:
image: redis:latest
expose:
- 6379
And I have the following connection string:
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=postgres;dbname=project',
'username' => 'project',
'password' => 'project',
'charset' => 'utf8',
'schemaMap' => [
'pgsql'=> [
'class'=>'yii\db\pgsql\Schema',
'defaultSchema' => 'public'
]
],
],
As you see I gave the "postgres" as a hostname, because in the docker-compose.yml I gave this as the database. But unfortunately I got this database exception, but why? How can I solve it?