Skip to content

Commit 9466bdc

Browse files
committed
Merge upstream PR#83 - container: :host networking mode
testcontainers#83
2 parents f7423e4 + ce8eaaf commit 9466bdc

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
@@ -71,7 +71,7 @@ Creates a testcontainers instance from a given Docker label and returns them
7171
| `:reuse` | Boolean | Should the container be reused, if another Testcontainer with identical config is started? |
7272
| `:env-vars` | Map | A map with environment variables |
7373
| `:command` | Vector with strings | The start command of the container |
74-
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`) |
74+
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`). For host networking, use :host |
7575
| `:network-aliases` | Map | A list of alias names for the container on the network |
7676
| `:wait-for` | Map | A map containing the [wait strategy](doc/wait-strategies.md) to use and the condition to check for |
7777
| `:log-to` | Map | A map containing the [log strategy](doc/log-strategies.md) to use, e.g. {:log-strategy string} |
@@ -142,7 +142,7 @@ Initializes a given Testcontainer, which was e.g. provided by a library
142142
| `:reuse` | Boolean | Should the container be reused, if another Testcontainer with identical config is started? |
143143
| `:env-vars` | Map | A map with environment variables |
144144
| `:command` | Vector with strings | The start command of the container |
145-
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`) |
145+
| `:network` | Map or :host | A map containing the configuration of a Docker Network (see: `create-network`). For host networking, use :host |
146146
| `:network-aliases` | Map | A list of alias names for the container on the network |
147147
| `:wait-for` | Map | A map containing the [wait strategy](doc/wait-strategies.md) to use and the condition to check for |
148148
| `:log-to` | Map | A map containing the [log strategy](doc/log-strategies.md) to use, e.g. {:log-strategy string} |
@@ -157,7 +157,7 @@ Initializes a given Testcontainer, which was e.g. provided by a library
157157
| `:reuse` | Boolean | Is this container reusable? |
158158
| `:env-vars` | Map | Value of the same input parameter |
159159
| `:host` | String | The host for the Docker Container |
160-
| `:network` | Map | The network configuration of the Container, if provided |
160+
| `:network` | Map or :host | The network configuration of the Container, if provided. |
161161
| `:wait-for` | Map | The wait-for configuration of the Container, if provided! |
162162

163163
#### Example:
@@ -198,7 +198,7 @@ Creates a testcontainer from a Dockerfile
198198
| `:reuse` | Boolean | Should the container be reused, if another Testcontainer with identical config is started? |
199199
| `:env-vars` | Map | A map with environment variables |
200200
| `:command` | Vector with strings | The start command of the container |
201-
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`) |
201+
| `:network` | Map | A map containing the configuration of a Docker Network (see: `create-network`). For host networking, use :host |
202202
| `:network-aliases` | Map | A list of alias names for the container on the network |
203203
| `:wait-for` | Map | A map containing the [wait strategy](doc/wait-strategies.md) to use and the condition to check for |
204204
| `:log-to` | Map | A map containing the [log strategy](doc/log-strategies.md) to use, e.g. {:log-strategy string} |
@@ -416,7 +416,7 @@ Creates a network. The optional map accepts config values for enabling ipv6 and
416416
| Key | Type | Description |
417417
| ------------- | :------------- | :----- |
418418
| `:ipv6` | boolean | Should the network enable IPv6? |
419-
| `:driver` | String | The network driver used by Docker, e.g. `bridge` or `host` |
419+
| `:driver` | String | The network driver used by Docker, e.g. `bridge` |
420420

421421
#### Result:
422422

src/testcontainers_clj/core.clj

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

206206
(when network
207-
(.setNetwork container (:network network)))
207+
(if (= :host network)
208+
(.withNetworkMode container "host")
209+
(.setNetwork container (:network network))))
208210

209211
(when network-aliases
210212
(.setNetworkAliases container network-aliases))

0 commit comments

Comments
 (0)