@@ -52,6 +52,7 @@ type Do struct {
5252 overlay bool
5353 uidMap idMapSlice
5454 gidMap idMapSlice
55+ volumes volumes
5556}
5657
5758// Name implements subcommands.Command.Name.
@@ -120,6 +121,24 @@ func (is *idMapSlice) Set(s string) error {
120121 return nil
121122}
122123
124+ type volumes []string
125+
126+ // Set implements flag.Value.Get.
127+ func (v * volumes ) Set (value string ) error {
128+ * v = append (* v , value )
129+ return nil
130+ }
131+
132+ // Get implements flag.Value.Get.
133+ func (v * volumes ) Get () any {
134+ return v
135+ }
136+
137+ // String implements flag.Value.String.
138+ func (v * volumes ) String () string {
139+ return strings .Join (* v , "," )
140+ }
141+
123142// SetFlags implements subcommands.Command.SetFlags.
124143func (c * Do ) SetFlags (f * flag.FlagSet ) {
125144 f .StringVar (& c .root , "root" , "/" , `path to the root directory, defaults to "/"` )
@@ -130,6 +149,7 @@ func (c *Do) SetFlags(f *flag.FlagSet) {
130149 f .BoolVar (& c .overlay , "force-overlay" , true , "use an overlay. WARNING: disabling gives the command write access to the host" )
131150 f .Var (& c .uidMap , "uid-map" , "Add a user id mapping [ContainerID, HostID, Size]" )
132151 f .Var (& c .gidMap , "gid-map" , "Add a group id mapping [ContainerID, HostID, Size]" )
152+ f .Var (& c .volumes , "volume" , "Add a volume path SRC[:DST]. This option can be used multiple times to add several volumes." )
133153}
134154
135155// Execute implements subcommands.Command.Execute.
@@ -190,6 +210,20 @@ func (c *Do) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommand
190210 "dev.gvisor.spec.rootfs.overlay" : "memory" ,
191211 }
192212 }
213+ for _ , v := range c .volumes {
214+ parts := strings .SplitN (v , ":" , 2 )
215+ var src , dst string
216+ if len (parts ) == 2 {
217+ src , dst = parts [0 ], parts [1 ]
218+ } else {
219+ src , dst = v , v
220+ }
221+ spec .Mounts = append (spec .Mounts , specs.Mount {
222+ Type : "bind" ,
223+ Source : src ,
224+ Destination : dst ,
225+ })
226+ }
193227
194228 cid := fmt .Sprintf ("runsc-%06d" , rand .Int31n (1000000 ))
195229
0 commit comments