Commit eb2803e
Improve Docker-in-Docker (DinD) support (#248)
* Improve Docker-in-Docker (DinD) support
- Add TESTCONTAINERS_HOST_OVERRIDE env var and tc.host.override property
to allow explicit host override, bypassing auto-detection
- Add TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE env var to override the
Docker socket path mounted into Ryuk
- Improve gateway fallback by parsing /proc/net/route when bridge
gateway inspection fails, instead of falling back to localhost
- Improve container detection by checking /proc/1/cgroup as fallback
when /.dockerenv doesn't exist (handles more container runtimes)
- Add unit tests for route parsing and container detection logic
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add connect timeout to Ryuk TCP socket
gen_tcp.connect had no timeout (default :infinity), causing an
indefinite hang when bridge gateway IP is unreachable due to hairpin
NAT issues in DooD environments. Add 5-second connect timeout.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fall back to container internal IP for Ryuk connection
When connecting to Ryuk via docker_hostname:mapped_port fails (common
in DooD environments due to hairpin NAT), fall back to connecting via
the container's internal IP on its internal port (8080). Both the test
runner container and Ryuk are on the same bridge network by default,
so direct IP access works reliably.
Also extracts try_tcp_connect/2 helper to reduce duplication.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Use container internal IPs in DooD environments
When running inside a container with a shared Docker socket (DooD),
the bridge gateway's mapped ports may be unreachable due to hairpin
NAT. This change detects that scenario at startup by probing the
gateway, and switches to "container networking mode" where:
- get_host(container) returns container.ip_address instead of gateway
- get_port(container, port) returns the internal port directly
All built-in container modules (postgres, mysql, redis, kafka, etc.)
now use these DooD-aware APIs, so tests work automatically in both
standard and DooD environments without any configuration.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix hardcoded hosts in tests and PortWaitStrategy
- PortWaitStrategy now uses get_host(container) and get_port(container)
at wait time, overriding the IP set at construction. This fixes
Selenium and EMQX containers in DooD.
- Update tests that hardcoded 127.0.0.1 or localhost to use the
DooD-aware APIs instead.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix remaining test failures in DooD
- Remove unused Container alias from kafka_container_test
- Skip host network test in DooD (inherently incompatible since host
networking binds to Docker host, not the test container)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fall back to mapped ports for containers on custom networks
In container_ip mode, containers on custom Docker networks are not
reachable from the test container via internal IP (different network).
Detect this via the container.network field and fall back to the
standard docker_hostname:mapped_port approach for those containers.
Also fix unused alias warnings in port_wait_strategy and
kafka_container_test.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix Kafka and Toxiproxy in DooD environments
Kafka: In DooD, clients connect to the container's internal IP so
Kafka must advertise on the internal port. Use a BROKER listener
name in container mode to avoid advertising the unreachable
bridge gateway address.
Toxiproxy test: Use get_host(container) instead of get_host() so
the API URL uses the correct host in DooD.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Tag DooD-incompatible tests with :dood_limitation
Tests that require custom Docker networks or have slow container
startup in nested Docker are tagged with @tag :dood_limitation and
automatically excluded when running inside a container.
Affected tests:
- Toxiproxy integration (custom network)
- Network hostname communication (custom network)
- EMQX custom config (slow startup timeout)
- Selenium (slow startup timeout)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix Kafka advertised listeners in DooD with after_start
Kafka needs to advertise an address reachable by clients. In DooD,
the container IP is only known after startup. Use after_start to
run kafka-configs.sh and update the advertised listener to
BROKER://container_ip:internal_port, so KafkaEx clients can resolve
the broker address correctly.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Tag Kafka integration tests as dood_limitation
Kafka's advertised.listeners cannot be dynamically updated to use
the container's internal IP after startup. This is a known limitation
that testcontainers-java solves with custom startup script injection.
Tag these tests for exclusion in DooD environments.
Also reverts the kafka-configs.sh after_start approach which doesn't
work reliably (not a dynamic config in KRaft mode).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Revert Kafka DooD listener changes
Since Kafka tests are tagged dood_limitation, the DooD-specific
listener config is dead code. Revert to original with_kraft_config.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Use @tag :dood_limitation for host network test
Replace runtime container check with tag-based exclusion, consistent
with all other DooD-incompatible tests. Restore original 127.0.0.1
since this test only runs outside containers.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent c61dcbf commit eb2803e
File tree
24 files changed
+433
-72
lines changed- lib
- container
- mix/tasks/testcontainers
- wait_strategy
- test
- container
- wait_strategy
24 files changed
+433
-72
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
| 195 | + | |
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
160 | | - | |
| 159 | + | |
| 160 | + | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
| 190 | + | |
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | | - | |
| 236 | + | |
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
| 196 | + | |
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
| 235 | + | |
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| |||
0 commit comments