cmd/sketch: add mount flag for container volumes
Add a mount flag that simplifies mounting host directories into the container.
When specified with format /path/on/host:/path/in/container it's automatically
converted to a docker volume mount argument (-v) in the docker invocation.
This simplifies volume mounting compared to the more generic docker-args flag.
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s67251d45fd28831ek
diff --git a/dockerimg/dockerimg.go b/dockerimg/dockerimg.go
index a6d012e..4b50ae1 100644
--- a/dockerimg/dockerimg.go
+++ b/dockerimg/dockerimg.go
@@ -99,6 +99,9 @@
// DockerArgs are additional arguments to pass to the docker create command
DockerArgs string
+ // Mounts specifies volumes to mount in the container in format /path/on/host:/path/in/container
+ Mounts []string
+
// ExperimentFlag contains the experimental features to enable
ExperimentFlag string
@@ -484,6 +487,13 @@
}
// colima does this by default, but Linux docker seems to need this set explicitly
cmdArgs = append(cmdArgs, "--add-host", "host.docker.internal:host-gateway")
+
+ // Add volume mounts if specified
+ for _, mount := range config.Mounts {
+ if mount != "" {
+ cmdArgs = append(cmdArgs, "-v", mount)
+ }
+ }
cmdArgs = append(
cmdArgs,
imgName,