github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/cmd/swarmctl/service/flagparser/bind.go (about)

     1  package flagparser
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/docker/swarmkit/api"
     8  	"github.com/spf13/pflag"
     9  )
    10  
    11  // parseBind only supports a very simple version of bind for testing the most
    12  // basic of data flows. Replace with a --mount flag, similar to what we have in
    13  // docker service.
    14  func parseBind(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
    15  	if flags.Changed("bind") {
    16  		binds, err := flags.GetStringSlice("bind")
    17  		if err != nil {
    18  			return err
    19  		}
    20  
    21  		container := spec.Task.GetContainer()
    22  
    23  		for _, bind := range binds {
    24  			parts := strings.SplitN(bind, ":", 2)
    25  			if len(parts) != 2 {
    26  				return fmt.Errorf("bind format %q not supported", bind)
    27  			}
    28  			container.Mounts = append(container.Mounts, api.Mount{
    29  				Type:   api.MountTypeBind,
    30  				Source: parts[0],
    31  				Target: parts[1],
    32  			})
    33  		}
    34  	}
    35  
    36  	return nil
    37  }