| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -848,6 +848,7 @@ public HostConfig withMemorySwappiness(Long memorySwappiness) { | |||
| 848 | 848 | * <li>'host': use the host network stack inside the container. Note: the host mode gives the container full access to local system | |
| 849 | 849 | * services such as D-bus and is therefore considered insecure.</li> | |
| 850 | 850 | * </ul> | |
| 851 | + * Any other value is interpreted as a custom network's name for this container to connect to. | ||
| 851 | 852 | */ | |
| 852 | 853 | public HostConfig withNetworkMode(String networkMode) { | |
| 853 | 854 | this.networkMode = networkMode; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -600,7 +600,7 @@ public CreateContainerResponse exec() throws NotFoundException, ConflictExceptio | |||
| 600 | 600 | containerNetwork.withAliases(aliases); | |
| 601 | 601 | } | |
| 602 | 602 | ||
| 603 | - if (containerNetwork != null) { | ||
| 603 | + if (containerNetwork != null && hostConfig.getNetworkMode() != null) { | ||
| 604 | 604 | networkingConfig = new NetworkingConfig() | |
| 605 | 605 | .withEndpointsConfig(singletonMap(hostConfig.getNetworkMode(), containerNetwork)); | |
| 606 | 606 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | import com.github.dockerjava.api.model.Link; | |
| 24 | 24 | import com.github.dockerjava.api.model.LogConfig; | |
| 25 | 25 | import com.github.dockerjava.api.model.Network; | |
| 26 | + import com.github.dockerjava.api.model.PortBinding; | ||
| 26 | 27 | import com.github.dockerjava.api.model.Ports; | |
| 27 | 28 | import com.github.dockerjava.api.model.Ports.Binding; | |
| 28 | 29 | import com.github.dockerjava.api.model.RestartPolicy; | |
@@ -1125,4 +1126,15 @@ public void shouldNotEncodeAuth() { | |||
| 1125 | 1126 | ||
| 1126 | 1127 | assertThat(jsonNode.get("authConfig"), nullValue()); | |
| 1127 | 1128 | } | |
| 1129 | + | ||
| 1130 | + @Test | ||
| 1131 | + public void shouldHandleANetworkAliasWithoutACustomNetworkGracefully() { | ||
| 1132 | + // Should not throw | ||
| 1133 | + dockerRule.getClient() | ||
| 1134 | + .createContainerCmd(DEFAULT_IMAGE) | ||
| 1135 | + .withAliases("hello-world") | ||
| 1136 | + .withHostConfig(newHostConfig()) | ||
| 1137 | + .withCmd("sleep", "9999") | ||
| 1138 | + .exec(); | ||
| 1139 | + } | ||
| 1128 | 1140 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments