diff --git a/src/Container/Container.php b/src/Container/Container.php index de71085..f8d0470 100644 --- a/src/Container/Container.php +++ b/src/Container/Container.php @@ -167,13 +167,7 @@ public function run(bool $wait = true): self $this->process = new Process($params); $this->process->mustRun(); - $inspect = new Process(['docker', 'inspect', $this->id]); - $inspect->mustRun(); - - /** @var ContainerInspectSingleNetwork|ContainerInspectMultipleNetworks $inspectedData */ - $inspectedData = json_decode($inspect->getOutput(), true, 512, JSON_THROW_ON_ERROR); - - $this->inspectedData = $inspectedData; + $this->inspectedData = $this->getContainerInspect($this->id); Registry::add($this); diff --git a/src/Trait/DockerContainerAwareTrait.php b/src/Trait/DockerContainerAwareTrait.php index 1d68db7..f5d2c61 100644 --- a/src/Trait/DockerContainerAwareTrait.php +++ b/src/Trait/DockerContainerAwareTrait.php @@ -24,11 +24,7 @@ trait DockerContainerAwareTrait protected function getContainerAddress(string $containerId, ?string $networkName = null, ?array $inspectedData = null): string { if (! is_array($inspectedData)) { - $process = new Process(['docker', 'inspect', $containerId]); - $process->mustRun(); - - /** @var ContainerInspect $inspectedData */ - $inspectedData = json_decode($process->getOutput(), true, 512, JSON_THROW_ON_ERROR); + $inspectedData = $this->getContainerInspect($containerId); } if (is_string($networkName)) { @@ -47,4 +43,19 @@ protected function getContainerAddress(string $containerId, ?string $networkName throw new UnexpectedValueException('Unable to find container IP address'); } + + /** + * @param string $containerId + * @return ContainerInspect + * + * @throws JsonException + */ + protected function getContainerInspect(string $containerId): array + { + $process = new Process(['docker', 'inspect', $containerId]); + $process->mustRun(); + + /** @var ContainerInspect */ + return json_decode($process->getOutput(), true, 512, JSON_THROW_ON_ERROR); + } }