Skip to content

Commit db79478

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 c9cffc8 commit db79478

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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:
@@ -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
@@ -200,7 +200,9 @@
200200
(.setCommand container ^"[Ljava.lang.String;" (into-array String command)))
201201

202202
(when network
203-
(.setNetwork container (:network network)))
203+
(if (= :host network)
204+
(.withNetworkMode container "host")
205+
(.setNetwork container (:network network))))
204206

205207
(when network-aliases
206208
(.setNetworkAliases container network-aliases))

0 commit comments

Comments
 (0)