关于yii2连接docker数据库问题

db.php配置本机ip无效,只能通过设置docker-compose.yml在对应的php配置下方引入对应的mysql,以下为例子:

php-7.0.28-fpm:

    image: "ubuntu/php-7.0.28:v3"

    container_name: php-7.0.28-fpm

    volumes:

        - /home/zyz/docker-environment/php-7.0.28/etc:/usr/local/php/etc

        - /home/zyz/docker-environment/php-7.0.28/logs:/usr/local/php/var/log

        - /home/zyz/docker-environment/nginx-1.10.3/html:/usr/local/nginx/html

    dns:

        - 223.6.6.6

        - 8.8.8.8

    ports:

        - "9000"

    links:

        - redis

        - mysql

    command: /usr/local/php/sbin/php-fpm --nodaemonize

    restart: always

然后再在对应的db.php配置对应上方docker配置的mysql的名称为对应的host

return [

    'class' => 'yii\db\Connection',

    'dsn' => 'mysql:host=mysql;dbname=yii;port:6606',

    'username' => 'root',

    'password' => 'zyz123',

    'charset' => 'utf8',

];

你可能感兴趣的:(关于yii2连接docker数据库问题)