diff --git a/cmd/analyze.go b/cmd/analyze.go index 323ef4f..27a897c 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -1121,7 +1121,7 @@ func (a *analyzeCommand) createTempRuleSet(path string, name string) error { } func (a *analyzeCommand) createContainerNetwork() (string, error) { - networkName := container.RandomName() + networkName := fmt.Sprintf("network-%v", container.RandomName()) args := []string{ "network", "create", @@ -1143,7 +1143,7 @@ func (a *analyzeCommand) createContainerNetwork() (string, error) { // TODO: create for each source input once accepting multiple apps is completed func (a *analyzeCommand) createContainerVolume() (string, error) { - volName := container.RandomName() + volName := fmt.Sprintf("volume-%v", container.RandomName()) input, err := filepath.Abs(a.input) if err != nil { return "", err @@ -1233,6 +1233,7 @@ func (a *analyzeCommand) RunProviders(ctx context.Context, networkName string, v container.WithEntrypointArgs(args...), container.WithDetachedMode(true), container.WithCleanup(a.cleanup), + container.WithName(fmt.Sprintf("provider-%v", container.RandomName())), container.WithNetwork(networkName), ) if err != nil { @@ -1257,6 +1258,7 @@ func (a *analyzeCommand) RunProviders(ctx context.Context, networkName string, v container.WithEntrypointArgs(args...), container.WithDetachedMode(true), container.WithCleanup(a.cleanup), + container.WithName(fmt.Sprintf("provider-%v", container.RandomName())), container.WithNetwork(fmt.Sprintf("container:%v", a.providerContainerNames[0])), ) if err != nil { diff --git a/cmd/cleanup.go b/cmd/cleanup.go index 04f448e..29b9086 100644 --- a/cmd/cleanup.go +++ b/cmd/cleanup.go @@ -37,8 +37,6 @@ func (a *analyzeCommand) RmNetwork(ctx context.Context) error { if a.networkName == "" { return nil } - a.log.V(1).Info("removing container network", - "network", a.networkName) cmd := exec.CommandContext( ctx, Settings.ContainerBinary, diff --git a/pkg/container/container.go b/pkg/container/container.go index 2fe8148..045e48c 100644 --- a/pkg/container/container.go +++ b/pkg/container/container.go @@ -162,7 +162,7 @@ func NewContainer() *container { stdout: []io.Writer{os.Stdout}, env: map[string]string{}, stderr: []io.Writer{os.Stderr}, - Name: RandomName(), + Name: "", NetworkName: "", // by default, remove the container after run() cleanup: true, @@ -191,6 +191,9 @@ func (c *container) Run(ctx context.Context, opts ...Option) error { if c.Name != "" { args = append(args, "--name") args = append(args, c.Name) + } else { + args = append(args, "--name") + args = append(args, RandomName()) } if c.NetworkName != "" { args = append(args, "--network")