about summary refs log tree commit diff
path: root/src/container.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/container.go')
-rw-r--r--src/container.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/container.go b/src/container.go
index c9a918f..29046e2 100644
--- a/src/container.go
+++ b/src/container.go
@@ -9,7 +9,7 @@ import (
 )
 
 const (
-	VPNNetworkName = "circus-vpnnet"
+	containerNetworkName = "circus-vpnnet"
 )
 
 type ChallengeContainer struct {
@@ -23,11 +23,14 @@ func (cc ChallengeContainer) startContainer() (address string, containerID strin
 	// Set up our context and Docker CLI connection
 	setupContext()
 	setupDockerCLI()
-	// Set up network
-	err = setupNetwork()
 
-	if err != nil {
-		return "", "", err
+	// Set up container network
+	if containerNetworkID == "" {
+		id, err := setupNetwork(containerNetworkName, true)
+		if (err != nil) {
+			return "", "", err
+		}
+		containerNetworkID = id
 	}
 
 	// Create container
@@ -37,8 +40,8 @@ func (cc ChallengeContainer) startContainer() (address string, containerID strin
 		Tty: false,
 	}, nil, &network.NetworkingConfig{
 		EndpointsConfig: map[string]*network.EndpointSettings{
-			VPNNetworkName: {
-				NetworkID: vpnNetworkID,
+			containerNetworkName: {
+				NetworkID: containerNetworkID,
 			},
 		},
 	}, "")
@@ -60,7 +63,7 @@ func (cc ChallengeContainer) startContainer() (address string, containerID strin
 	}
 
 	// Return IP, Container ID and error
-	return inspectJSON.NetworkSettings.Networks[VPNNetworkName].IPAddress, resp.ID,nil
+	return inspectJSON.NetworkSettings.Networks[containerNetworkName].IPAddress, resp.ID,nil
 }
 
 // Stops the container with a timeout of one second