diff --git a/README.md b/README.md index 393ea4b..cac4d08 100644 --- a/README.md +++ b/README.md @@ -53,3 +53,29 @@ $ * Data goes in `$HOME/.var/serverctl` +### How can I tell a container to connect to another container? + +**Static configuration** + +If you need to preconfigure a connection, use the *DOCKER_HOST* environment +variable. It will only work in the *environment* section of the service config: + +```json + "environment": { + "FOO_SERVER": "${DOCKER_HOST}" + } +``` + +**From running container** + +Lookup the IP on your host. On Linux you would do something like: + +``` +$ ip addr show docker0 +6: docker0: mtu 1500 qdisc noqueue state UP group default + link/ether 02:42:69:cd:44:2c brd ff:ff:ff:ff:ff:ff + inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 + valid_lft forever preferred_lft forever + inet6 fe80::42:69ff:fecd:442c/64 scope link + valid_lft forever preferred_lft forever +``` diff --git a/src/Commands/StopCommand.php b/src/Commands/StopCommand.php index 0c7cd22..5f82b23 100644 --- a/src/Commands/StopCommand.php +++ b/src/Commands/StopCommand.php @@ -16,8 +16,9 @@ class StopCommand extends Command protected function configure() { + $this->addOption("all", "A", InputOption::VALUE_NONE, "Stop all services"); $this->addOption("instance", "i", InputOption::VALUE_REQUIRED, "Specify the instance name", "default"); - $this->addArgument("service", InputArgument::REQUIRED, "The service name"); + $this->addArgument("service", InputArgument::OPTIONAL, "The service name"); } protected function execute(InputInterface $input, OutputInterface $output) @@ -28,6 +29,26 @@ class StopCommand extends Command $serviceName = $input->getArgument("service"); $instanceName = $input->getOption("instance"); + $stopAll = $input->getOption("all"); + + if (!($instanceName || $stopAll)) { + $output->writeln("You need to specify a service, or --all"); + return self::FAILURE; + } + + if ($stopAll) { + $services = $containerManager->getRunningServices(); + foreach ($services as $service) { + $output->write("Stopping...\r"); + try { + $containerManager->stopService($service['service'], $service['instance']); + $output->writeln("Stopped service ".$service['service']['name']."[".$service['instance']."]"); + } catch (RuntimeException $e) { + $output->writeln("".$e->getMessage().""); + } + } + return self::SUCCESS; + } $serviceInfo = $serviceRegistry->findServiceByName($serviceName); if (!$serviceInfo) {