@@ -210,21 +210,33 @@ func ValidateDockerFirewallAllowsContainerToContainerCommunication(ctx context.C
210210 if err != nil {
211211 return err
212212 }
213+
214+ // Create a docker network
215+ networkName := "firewall-test-network"
216+ createNetworkCmd := fmt .Sprintf (
217+ "%s network create %s" ,
218+ dockerCmd , networkName ,
219+ )
220+ _ , stderr , err := sshClient .RunCommand (ctx , createNetworkCmd )
221+ if err != nil {
222+ return fmt .Errorf ("failed to create docker network: %w, stderr: %s" , err , stderr )
223+ }
224+
213225 // Start a Docker container in the background
214226 containerName := fmt .Sprintf ("firewall-test-container-to-container" )
215227 startDockerCmd := fmt .Sprintf (
216- "%s run -d --name %s nginx:alpine" ,
217- dockerCmd , containerName ,
228+ "%s run -d --name %s --network %s nginx:alpine" ,
229+ dockerCmd , containerName , networkName ,
218230 )
219- _ , stderr , err : = sshClient .RunCommand (ctx , startDockerCmd )
231+ _ , stderr , err = sshClient .RunCommand (ctx , startDockerCmd )
220232 if err != nil {
221233 return fmt .Errorf ("failed to start docker container: %w, stderr: %s" , err , stderr )
222234 }
223235
224236 // Start a second Docker container to connect to the first container
225237 startDockerCmd = fmt .Sprintf (
226- "%s run --rm alpine wget -q -O- http://%s" ,
227- dockerCmd , containerName ,
238+ "%s run --network %s -- rm alpine wget -q -O- http://%s" ,
239+ dockerCmd , networkName , containerName ,
228240 )
229241 stdout , stderr , err := sshClient .RunCommand (ctx , startDockerCmd )
230242 if err != nil {
0 commit comments