MCPcopy Create free account
hub / github.com/docker/cli / handleVolumeToMount

Function handleVolumeToMount

cli/compose/convert/volume.go:37–92  ·  view source on GitHub ↗
(
	volume composetypes.ServiceVolumeConfig,
	stackVolumes volumes,
	namespace Namespace,
)

Source from the content-addressed store, hash-verified

35}
36
37func handleVolumeToMount(
38 volume composetypes.ServiceVolumeConfig,
39 stackVolumes volumes,
40 namespace Namespace,
41) (mount.Mount, error) {
42 result := createMountFromVolume(volume)
43
44 if volume.Image != nil {
45 return mount.Mount{}, errors.New("images options are incompatible with type volume")
46 }
47 if volume.Tmpfs != nil {
48 return mount.Mount{}, errors.New("tmpfs options are incompatible with type volume")
49 }
50 if volume.Bind != nil {
51 return mount.Mount{}, errors.New("bind options are incompatible with type volume")
52 }
53 if volume.Cluster != nil {
54 return mount.Mount{}, errors.New("cluster options are incompatible with type volume")
55 }
56 // Anonymous volumes
57 if volume.Source == "" {
58 return result, nil
59 }
60
61 stackVolume, exists := stackVolumes[volume.Source]
62 if !exists {
63 return mount.Mount{}, fmt.Errorf("undefined volume %q", volume.Source)
64 }
65
66 result.Source = namespace.Scope(volume.Source)
67 result.VolumeOptions = &mount.VolumeOptions{}
68
69 if volume.Volume != nil {
70 result.VolumeOptions.NoCopy = volume.Volume.NoCopy
71 result.VolumeOptions.Subpath = volume.Volume.Subpath
72 }
73
74 if stackVolume.Name != "" {
75 result.Source = stackVolume.Name
76 }
77
78 // External named volumes
79 if stackVolume.External.External {
80 return result, nil
81 }
82
83 result.VolumeOptions.Labels = addStackLabel(namespace, stackVolume.Labels)
84 if stackVolume.Driver != "" || stackVolume.DriverOpts != nil {
85 result.VolumeOptions.DriverConfig = &mount.Driver{
86 Name: stackVolume.Driver,
87 Options: stackVolume.DriverOpts,
88 }
89 }
90
91 return result, nil
92}
93
94func handleImageToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, error) {

Callers 1

convertVolumeToMountFunction · 0.85

Calls 3

createMountFromVolumeFunction · 0.85
addStackLabelFunction · 0.85
ScopeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…