geerlingguy / jeffgeerling-com

Drupal Codebase for JeffGeerling.com
https://www.jeffgeerling.com
GNU General Public License v2.0
40 stars 2 forks source link

Figure out how to connect to legacy Drupal 7 database from local Docker environment #5

Closed geerlingguy closed 4 years ago

geerlingguy commented 4 years ago

Currently, I have the legacy database running via Docker on 127.0.0.1 on my host machine, port 3307. If I try connecting with the configuration below in settings.php, I get a connection error:

$databases['drupal7']['default'] = array (
  'database' => 'drupal',
  'username' => 'drupal',
  'password' => 'drupal',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3307',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

With the drush command:

vendor/bin/drush migrate-upgrade --legacy-db-key=drupal7 --legacy-root=https://www.jeffgeerling.com --configure-only

I also tried connecting directly via the mysql client on the CLI inside the Docker container, and couldn't connect either with localhost, 127.0.0.1, drupal7 (the name of the Docker container that had the legacy database), or any other string I could think to use (I set --port=3307 too, along with the other connection details).

So I need to see how I can connect from one Docker container running Drupal to another Docker container (in a different Docker Compose setup / network) over the host network on port 3307. Maybe check into the network IPs? I think I have a custom bridged network set up for the Drupal 7 site...

geerlingguy commented 4 years ago

Aha! I can connect using the sneaky Docker for Mac localhost bridge DNS name:

mysql -u drupal -pdrupal -P 3307 -h docker.for.mac.localhost drupal

So the 'host' should be docker.for.mac.localhost.

geerlingguy commented 4 years ago

Going to shelve this issue for now (so I can show the full debugging process in the next LIVE stream on the 18th), but I'm getting:

root@0de08bb03dcd:/var/www/html# vendor/bin/drush migrate-upgrade --legacy-db-key=drupal7 --legacy-root=https://www.jeffgeerling.com --configure-only
 [error]  Error: Call to undefined function Drupal\migrate_upgrade\drush_print() in Drupal\migrate_upgrade\MigrateUpgradeDrushRunner->export() (line 311 of /var/www/html/web/modules/contrib/migrate_upgrade/src/MigrateUpgradeDrushRunner.php) #0 /var/www/html/web/modules/contrib/migrate_upgrade/src/Commands/MigrateUpgradeCommands.php(61): Drupal\migrate_upgrade\MigrateUpgradeDrushRunner->export()
#1 [internal function]: Drupal\migrate_upgrade\Commands\MigrateUpgradeCommands->upgrade(Array)

Related to: Make migrate_upgrade compatible with Drush 10

So it looks like I'll either need to downgrade to Drush 9 or apply the patch from that issue. Maybe do the patch apply and show how that's done via composer-patches, since a lot of people will need to maintain patches to get little bits and pieces working correctly.

geerlingguy commented 4 years ago

Fixed via the above commit (using Drush 9.7.x), and also updating the settings.php file to use the docker for mac localhost DNS shortcut.