Skip to content

Commit ce8eaaf

Browse files
committed
container: :host networking mode
Host networking is unique from the other network drivers. It requires the container to run (.withNetworkMode "host"). Trying to create a docker network with the "host" driver does not work. This adds a special keyword `:host` which may be set as the container :network.
1 parent 802f18a commit ce8eaaf

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Creates a testcontainers instance from a given Docker label and returns them
7474
| `:exposed-ports` | Vector with ints, mandatory | All ports which should be exposed and mapped to a local port |
7575
| `:env-vars` | Map | A map with environment variables |
7676
| `:command` | Vector with strings | The start command of the container |
77-
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`) |
77+
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`). For host networking, use :host |
7878
| `:network-aliases` | Map | A list of alias names for the container on the network |
7979
| `:wait-for` | Map | A map containing the [wait strategy](doc/wait-strategies.md) to use and the condition to check for |
8080
| `:log-to` | Map | A map containing the [log strategy](doc/log-strategies.md) to use, e.g. {:log-strategy string} |
@@ -129,10 +129,10 @@ Initializes a given Testcontainer, which was e.g. provided by a library
129129
| `:exposed-ports` | Vector with ints, mandatory | All ports which should be exposed and mapped to a local port |
130130
| `:env-vars` | Map | A map with environment variables |
131131
| `:command` | Vector with strings | The start command of the container |
132-
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`) |
132+
| `:network` | Map or :host | A map containing the configuration of a Docker Network (see: `create-network`). For host networking, use :host |
133133
| `:network-aliases` | Map | A list of alias names for the container on the network |
134-
| `:wait-for` | Map | A map containing the [wait strategy](doc/wait-strategies.md) to use and the condition to check for |
135-
| `:log-to` | Map | A map containing the [log strategy](doc/log-strategies.md) to use, e.g. {:log-strategy string} |
134+
| `:wait-for` | Map | A map containing the [wait strategy](doc/wait-strategies.md) to use and the condition to check for |
135+
| `:log-to` | Map | A map containing the [log strategy](doc/log-strategies.md) to use, e.g. {:log-strategy string} |
136136
| | | |
137137

138138
#### Result:
@@ -143,7 +143,7 @@ Initializes a given Testcontainer, which was e.g. provided by a library
143143
| `:exposed-ports` | Vector with ints | Value of the same input parameter |
144144
| `:env-vars` | Map | Value of the same input parameter |
145145
| `:host` | String | The host for the Docker Container |
146-
| `:network` | Map | The network configuration of the Container, if provided |
146+
| `:network` | Map or :host | The network configuration of the Container, if provided. |
147147
| `:wait-for` | Map | The wait-for configuration of the Container, if provided! |
148148

149149
#### Example:
@@ -183,7 +183,7 @@ Creates a testcontainer from a Dockerfile
183183
| `:exposed-ports` | Vector with ints, mandatory | All ports which should be exposed and mapped to a local port |
184184
| `:env-vars` | Map | A map with environment variables |
185185
| `:command` | Vector with strings | The start command of the container |
186-
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`) |
186+
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`). For host networking, use :host |
187187
| `:network-aliases` | Map | A list of alias names for the container on the network |
188188
| `:wait-for` | Map | A map containing the [wait strategy](doc/wait-strategies.md) to use and the condition to check for |
189189
| `:log-to` | Map | A map containing the [log strategy](doc/log-strategies.md) to use, e.g. {:log-strategy string} |
@@ -399,7 +399,7 @@ Creates a network. The optional map accepts config values for enabling ipv6 and
399399
| Key | Type | Description |
400400
| ------------- | :------------- | :----- |
401401
| `:ipv6` | boolean | Should the network enable IPv6? |
402-
| `:driver` | String | The network driver used by Docker, e.g. `bridge` or `host` |
402+
| `:driver` | String | The network driver used by Docker, e.g. `bridge` |
403403

404404
#### Result:
405405

src/clj_test_containers/core.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@
198198
(.setCommand container ^"[Ljava.lang.String;" (into-array String command)))
199199

200200
(when network
201-
(.setNetwork container (:network network)))
201+
(if (= :host network)
202+
(.withNetworkMode container "host")
203+
(.setNetwork container (:network network))))
202204

203205
(when network-aliases
204206
(.setNetworkAliases container network-aliases))

0 commit comments

Comments
 (0)