diff --git a/pkg/docker/Create.go b/pkg/docker/Create.go index 9f0269c..15fc018 100644 --- a/pkg/docker/Create.go +++ b/pkg/docker/Create.go @@ -334,16 +334,30 @@ func (h *SidecarHandler) CreateHandler(w http.ResponseWriter, r *http.Request) { dindImage = "docker:dind" } + // create a dedicated docker network for the dind container + shell := exec.ExecTask{ + Command: "docker", + Args: []string{"network", "create", "--driver", "bridge", string(data.Pod.UID) + "_dind_network"}, + Shell: true, + } + execReturn, err = shell.Execute() + if err != nil { + HandleErrorAndRemoveData(h, w, "An error occurred during the creation of the network for the DIND container", err, "", "") + return + } + dindContainerArgs := []string{"run"} dindContainerArgs = append(dindContainerArgs, gpuArgsAsArray...) if _, err := os.Stat("/cvmfs"); err == nil { dindContainerArgs = append(dindContainerArgs, "-v", "/cvmfs:/cvmfs") } + // add the network to the dind container + dindContainerArgs = append(dindContainerArgs, "--network", string(data.Pod.UID)+"_dind_network") dindContainerArgs = append(dindContainerArgs, "--privileged", "-v", wd+":/"+wd, "-v", "/home:/home", "-v", "/var/lib/docker/overlay2:/var/lib/docker/overlay2", "-v", "/var/lib/docker/image:/var/lib/docker/image", "-d", "--name", string(data.Pod.UID)+"_dind", dindImage) var dindContainerID string - shell := exec.ExecTask{ + shell = exec.ExecTask{ Command: "docker", Args: dindContainerArgs, Shell: true, diff --git a/pkg/docker/Delete.go b/pkg/docker/Delete.go index 65b2662..3dccee8 100644 --- a/pkg/docker/Delete.go +++ b/pkg/docker/Delete.go @@ -113,6 +113,21 @@ func (h *SidecarHandler) DeleteHandler(w http.ResponseWriter, r *http.Request) { // check if the container has GPU devices attacched using the GpuManager and release them h.GpuManager.Release(containerName) + // delete also the network of the docker dind container that is called string(data.Pod.UID) + "_dind_network" + cmd = []string{"network", "rm", podUID + "_dind_network"} + shell = exec.ExecTask{ + Command: "docker", + Args: cmd, + Shell: true, + } + execReturn, _ = shell.Execute() + execReturn.Stdout = strings.ReplaceAll(execReturn.Stdout, "\n", "") + if execReturn.Stderr != "" { + log.G(h.Ctx).Error("\u274C [DELETE CALL] Error deleting network " + podUID + "_dind_network") + } else { + log.G(h.Ctx).Info("\u2705 [DELETE CALL] Deleted network " + podUID + "_dind_network") + } + wd, err := os.Getwd() if err != nil { HandleErrorAndRemoveData(h, w, "Unable to get current working directory", err, "", "")