Run executes a docker command with the given arguments. It automatically handles verbose logging and working directory configuration.
(args ...string)
| 52 | // Run executes a docker command with the given arguments. |
| 53 | // It automatically handles verbose logging and working directory configuration. |
| 54 | func (d *DockerExecutor) Run(args ...string) error { |
| 55 | if d.Verbose { |
| 56 | fmt.Printf("Running: docker %s\n", strings.Join(args, " ")) |
| 57 | if d.WorkDir != "" { |
| 58 | fmt.Printf("Working directory: %s\n", d.WorkDir) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | cmd := exec.Command("docker", args...) |
| 63 | if d.WorkDir != "" { |
| 64 | cmd.Dir = d.WorkDir |
| 65 | } |
| 66 | cmd.Stdout = os.Stdout |
| 67 | cmd.Stderr = os.Stderr |
| 68 | |
| 69 | return cmd.Run() |
| 70 | } |
| 71 | |
| 72 | // Build builds a Docker image with the specified name and context. |
| 73 | // Additional build arguments can be provided (e.g., "--platform", "linux/amd64"). |