Skip to content

Commit 2bc3d13

Browse files
committed
cmd/run: Add --arch flag for container architecture selection
Add the --arch / -a flag to the run command, allowing users to run commands inside cross-architecture containers by specifying the target architecture (e.g., toolbox run --arch arm64 uname -m). Can be used with flags --distro and --release, just as for container creation. The flag value is resolved through resolveArchitectureID() (added in [1]) and passed to resolveContainerAndImageNames() (updated for cross-arch in [1]) so that it resolves to the architecture-suffixed container name. [1] containers#1786 containers#1789 Signed-off-by: Dalibor Kricka <dalidalk@seznam.cz>
1 parent 90e5e66 commit 2bc3d13

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/cmd/run.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type entryPointError struct {
5353

5454
var (
5555
runFlags struct {
56+
arch string
5657
container string
5758
distro string
5859
preserveFDs uint
@@ -74,6 +75,12 @@ func init() {
7475
flags := runCmd.Flags()
7576
flags.SetInterspersed(false)
7677

78+
flags.StringVarP(&runFlags.arch,
79+
"arch",
80+
"a",
81+
"",
82+
"Run command inside a Toolbx container for a different architecture than the host")
83+
7784
flags.StringVarP(&runFlags.container,
7885
"container",
7986
"c",
@@ -142,12 +149,17 @@ func run(cmd *cobra.Command, args []string) error {
142149

143150
command := args
144151

152+
archID, err := resolveArchitectureID(runFlags.arch, "")
153+
if err != nil {
154+
return err
155+
}
156+
145157
container, image, release, err := resolveContainerAndImageNames(runFlags.container,
146158
"--container",
147159
runFlags.distro,
148160
"",
149161
runFlags.release,
150-
architecture.HostArchID)
162+
archID)
151163

152164
if err != nil {
153165
return err

0 commit comments

Comments
 (0)