yiisoft / yii2-app-advanced

Yii 2.0 Advanced Application Template
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
1.66k stars 1.28k forks source link

docker-compose run --rm backend php yii migrate does not work #458

Closed fleduc closed 4 years ago

fleduc commented 4 years ago

I'm trying to start a new Yii2 advanced project using Docker.

Since I'm only using Docker on my local dev environment (no Php, Composer, etc installed locally), I've followed your "Installing using Docker" procedure found here

As per your procedure, in my console (Cmder).

Running this command worked docker-compose run --rm backend composer install

Running this command worked docker-compose run --rm backend php /app/init

Running this command DID NOT work docker-compose run --rm backend php yii migrate

Error message: usermod: no changes Yii Migration Tool (based on Yii v2.0.33-dev)

Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known'

in /app/vendor/yiisoft/yii2/db/Connection.php:635 ...

Note: Running the exact same script on a Win10 Pro using Docker Desktop, worked on the first time.

Can somebody help me here?

Thanks

Additional info

Q A
Yii version 2
PHP version 7.2
Operating system Win10 Pro
VM VirtualBox-DockerToolbox
fleduc commented 4 years ago

Our investigations demonstrate that, on DockerToolbox, the "run --rm" command bring php container to start and terminate before the mysql container could initialize its connection.

This situation was resolved by inverting these steps in the procedure:

Start the application

docker-compose up -d

Run the migrations

docker-compose run --rm backend php yii migrate

michalrogalskiappwise commented 4 years ago

I'm running the following command in console:

docker-compose run --rm backend php init

Everything is just fine, so I'm changing access data in the main-local.php file:

'components' => [ 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=127.0.0.1;port=3396;dbname=pdo_local', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'enableQueryCache' => false, 'emulatePrepare' => false, ] ]

I'm running the next command:

docker-compose run --rm backend yii migrate

and there is an ERROR:

usermod: no changes Yii Migration Tool (based on Yii v2.0.32)

Exception 'yii\base\InvalidConfigException' with message 'Failed to instantiate component or class "db".'

in /app/vendor/yiisoft/yii2/di/Container.php:449

Stack trace: #0 /app/vendor/yiisoft/yii2/di/Container.php(374): yii\di\Container->getDependencies('db') #1 /app/vendor/yiisoft/yii2/di/Container.php(159): yii\di\Container->build('db', Array, Array) #2 /app/vendor/yiisoft/yii2/di/Instance.php(167): yii\di\Container->get('db') #3 /app/vendor/yiisoft/yii2/di/Instance.php(137): yii\di\Instance->get(NULL) #4 /app/vendor/yiisoft/yii2/console/controllers/MigrateController.php(183): yii\di\Instance::ensure(Object(yii\di\Instance), 'yii\\db\\Connecti...') #5 /app/vendor/yiisoft/yii2/base/Controller.php(155): yii\console\controllers\MigrateController- ->beforeAction(Object(yii\base\InlineAction)) #6 /app/vendor/yiisoft/yii2/console/Controller.php(164): yii\base\Controller->runAction('', Array) #7 /app/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('', Array) #8 /app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate', Array) #9 /app/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application ->runAction('migrate', Array) #10 /app/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application- ->handleRequest(Object(yii\console\Request)) #11 /app/vendor/yiisoft/yii2/yii(37): yii\base\Application->run() #12 {main}