diff --git a/monitor/commands/exec.go b/monitor/commands/exec.go index 1b9dd4db..7a0abe28 100644 --- a/monitor/commands/exec.go +++ b/monitor/commands/exec.go @@ -35,6 +35,9 @@ COMMAND and ARG... will be executed in the container. } func (cm *ExecCmd) Exec(ctx context.Context, args []string) error { + if ref := cm.m.AttachedSessionID(); ref == "" { + return errors.Errorf("no attaching session") + } if len(args) < 2 { return errors.Errorf("command must be passed") } diff --git a/monitor/commands/rollback.go b/monitor/commands/rollback.go index 0ac986a4..d56e4161 100644 --- a/monitor/commands/rollback.go +++ b/monitor/commands/rollback.go @@ -7,6 +7,7 @@ import ( controllerapi "github.com/docker/buildx/controller/pb" "github.com/docker/buildx/monitor/types" + "github.com/pkg/errors" ) type RollbackCmd struct { @@ -37,6 +38,9 @@ COMMAND and ARG... will be executed in the container. } func (cm *RollbackCmd) Exec(ctx context.Context, args []string) error { + if ref := cm.m.AttachedSessionID(); ref == "" { + return errors.Errorf("no attaching session") + } cfg := cm.invokeConfig if len(args) >= 2 { cmds := args[1:]