Last active
August 29, 2015 13:58
-
-
Save sdbondi/9930246 to your computer and use it in GitHub Desktop.
Use PhpPgMyAdmin to detect your docker postgres instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# phppgmyadmin/conf/config.inc.php | |
(...) | |
// Docker postgres connections | |
$server_i = 1; | |
$containers = explode("\n", trim(`docker ps`)); | |
array_shift($containers); | |
foreach ($containers as $cid) { | |
if (!preg_match('/postgres/', $cid)) { continue; } | |
$cid = substr($cid, 0, 12); | |
$container = json_decode(`docker inspect {$cid}`); | |
if ($container) { | |
$container = $container[0]; | |
$port = array_keys((Array)$container->NetworkSettings->Ports)[0]; | |
$port = +explode('/', $port, 2)[0]; | |
$conf['servers'][$server_i]['desc'] = substr($container->Name, 1); | |
$conf['servers'][$server_i]['host'] = $container->NetworkSettings->IPAddress; | |
$conf['servers'][$server_i]['port'] = $port; | |
$conf['servers'][$server_i]['sslmode'] = 'allow'; | |
$conf['servers'][$server_i]['defaultdb'] = 'template1'; | |
$conf['servers'][$server_i]['pg_dump_path'] = '/usr/bin/pg_dump'; | |
$conf['servers'][$server_i]['pg_dumpall_path'] = '/usr/bin/pg_dumpall'; | |
$server_i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes your containers are running and have 'postgres' in their image name or container name.