From 1f7d234c800626b2958dadf1a88c48cfb684f9b6 Mon Sep 17 00:00:00 2001 From: Andy Zhou Date: Fri, 31 May 2019 02:03:35 -0700 Subject: [PATCH] Add k3d- prefix to docker network name Should make sense since all container names are with the same prefix. --- cli/container.go | 4 ++-- cli/network.go | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/container.go b/cli/container.go index 898f8cee..eb097b20 100644 --- a/cli/container.go +++ b/cli/container.go @@ -105,7 +105,7 @@ func createServer(verbose bool, image string, apiPort string, args []string, env networkingConfig := &network.NetworkingConfig{ EndpointsConfig: map[string]*network.EndpointSettings{ - name: { + k3dNetworkName(name): { Aliases: []string{containerName}, }, }, @@ -175,7 +175,7 @@ func createWorker(verbose bool, image string, args []string, env []string, name networkingConfig := &network.NetworkingConfig{ EndpointsConfig: map[string]*network.EndpointSettings{ - name: { + k3dNetworkName(name): { Aliases: []string{containerName}, }, }, diff --git a/cli/network.go b/cli/network.go index f1d8aa91..6a1813e5 100644 --- a/cli/network.go +++ b/cli/network.go @@ -10,6 +10,10 @@ import ( "github.com/docker/docker/client" ) +func k3dNetworkName(clusterName string) string { + return fmt.Sprintf("k3d-%s", clusterName) +} + // createClusterNetwork creates a docker network for a cluster that will be used // to let the server and worker containers communicate with each other easily. func createClusterNetwork(clusterName string) (string, error) { @@ -36,7 +40,7 @@ func createClusterNetwork(clusterName string) (string, error) { } // create the network with a set of labels and the cluster name as network name - resp, err := docker.NetworkCreate(ctx, clusterName, types.NetworkCreate{ + resp, err := docker.NetworkCreate(ctx, k3dNetworkName(clusterName), types.NetworkCreate{ Labels: map[string]string{ "app": "k3d", "cluster": clusterName,