|
23 | 23 |
|
24 | 24 | import com.github.dockerjava.api.DockerClient;
|
25 | 25 | import com.github.dockerjava.api.command.InspectContainerResponse;
|
| 26 | +import com.github.dockerjava.api.exception.NotFoundException; |
26 | 27 | import com.github.dockerjava.api.model.ContainerNetwork;
|
27 | 28 |
|
28 | 29 | final class PostgresUtils {
|
@@ -120,15 +121,20 @@ static ContainerAndNetwork findDockerContainer(String host) {
|
120 | 121 |
|
121 | 122 | return client.listContainersCmd().exec().stream()
|
122 | 123 | .map(container -> {
|
123 |
| - InspectContainerResponse inspectContainerResponse = client.inspectContainerCmd(container.getId()).exec(); |
124 |
| - for (ContainerNetwork network : inspectContainerResponse.getNetworkSettings().getNetworks().values()) { |
125 |
| - if (network.getAliases() != null && network.getAliases().contains(host)) { |
126 |
| - log.debug("Found Docker container {} with network {}", |
127 |
| - String.join(", ", container.getNames()), network.getNetworkID()); |
128 |
| - return new ContainerAndNetwork(inspectContainerResponse, network); |
| 124 | + try { |
| 125 | + InspectContainerResponse inspectContainerResponse = client.inspectContainerCmd(container.getId()).exec(); |
| 126 | + for (ContainerNetwork network : inspectContainerResponse.getNetworkSettings().getNetworks().values()) { |
| 127 | + if (network.getAliases() != null && network.getAliases().contains(host)) { |
| 128 | + log.debug("Found Docker container {} with network {}", |
| 129 | + String.join(", ", container.getNames()), network.getNetworkID()); |
| 130 | + return new ContainerAndNetwork(inspectContainerResponse, network); |
| 131 | + } |
129 | 132 | }
|
| 133 | + return null; |
| 134 | + } catch (NotFoundException e) { |
| 135 | + log.debug("Docker container '{}' seems to be gone", container.getId(), e); |
| 136 | + return null; |
130 | 137 | }
|
131 |
| - return null; |
132 | 138 | })
|
133 | 139 | .filter(Objects::nonNull)
|
134 | 140 | .findFirst()
|
|
0 commit comments