exec constructs/executes the `nerdctl exec` command to be executed on the given container.
(ctx context.Context, container containerd.Container, eo ExecOptions)
| 84 | |
| 85 | // exec constructs/executes the `nerdctl exec` command to be executed on the given container. |
| 86 | func (c *Composer) exec(ctx context.Context, container containerd.Container, eo ExecOptions) error { |
| 87 | args := []string{ |
| 88 | "exec", |
| 89 | fmt.Sprintf("--detach=%t", eo.Detach), |
| 90 | fmt.Sprintf("--interactive=%t", eo.Interactive), |
| 91 | fmt.Sprintf("--tty=%t", eo.Tty), |
| 92 | fmt.Sprintf("--privileged=%t", eo.Privileged), |
| 93 | } |
| 94 | if eo.User != "" { |
| 95 | args = append(args, "--user", eo.User) |
| 96 | } |
| 97 | if eo.WorkDir != "" { |
| 98 | args = append(args, "--workdir", eo.WorkDir) |
| 99 | } |
| 100 | for _, e := range eo.Env { |
| 101 | args = append(args, "--env", e) |
| 102 | } |
| 103 | args = append(args, container.ID()) |
| 104 | args = append(args, eo.Args...) |
| 105 | cmd := c.createNerdctlCmd(ctx, args...) |
| 106 | |
| 107 | if eo.Interactive { |
| 108 | cmd.Stdin = os.Stdin |
| 109 | } |
| 110 | if !eo.Detach { |
| 111 | cmd.Stdout = os.Stdout |
| 112 | cmd.Stderr = os.Stderr |
| 113 | } |
| 114 | |
| 115 | if c.DebugPrintFull { |
| 116 | log.G(ctx).Debugf("Executing %v", cmd.Args) |
| 117 | } |
| 118 | return cmd.Run() |
| 119 | } |
no test coverage detected