1- import pytest
21import time
32import socket
43from testcontainers .core .container import DockerContainer
98def _wait_for_dind_return_ip (client , dind ):
109 # get ip address for DOCKER_HOST
1110 # avoiding DockerContainer class here to prevent code changes affecting the test
12- specs = client .get_container (dind .id )
13- docker_host_ip = specs ['NetworkSettings' ]['Networks' ]['bridge' ]['IPAddress' ]
11+ docker_host_ip = client .bridge_ip (dind .id )
1412 # Wait for startup
1513 timeout = 10
1614 start_wait = time .perf_counter ()
@@ -57,7 +55,10 @@ def test_wait_for_logs_docker_in_docker():
5755
5856def test_dind_inherits_network ():
5957 client = DockerClient ()
60- custom_network = client .client .networks .create ("custom_network" , driver = "bridge" )
58+ try :
59+ custom_network = client .client .networks .create ("custom_network" , driver = "bridge" , check_duplicate = True )
60+ except :
61+ custom_network = client .client .networks .list (names = ["custom_network" ])[0 ]
6162 dind = client .run (
6263 image = "docker:dind" ,
6364 command = "dockerd -H tcp://0.0.0.0:2375 --tls=false" ,
@@ -82,7 +83,7 @@ def test_dind_inherits_network():
8283 }) as container :
8384 assert container .get_container_host_ip () == docker_host_ip
8485 # Check the gateways are the same, so they can talk to each other
85- assert client .gateway_ip (container .id ) == client .gateway_ip (dind .id )
86+ assert client .gateway_ip (container .get_wrapped_container (). id ) == client .gateway_ip (dind .id )
8687 wait_for_logs (container , "Hello from Docker!" )
8788 stdout , stderr = container .get_logs ()
8889 assert stdout , 'There should be something on stdout'
0 commit comments