Create mount source if it does not exist#1563
Create mount source if it does not exist#1563aiordache wants to merge 2 commits intodocker-archive:mainfrom
Conversation
ndeloof
left a comment
There was a problem hiding this comment.
incorrect implementation creating source on CLI hosts, not Dockerd hosts
| if m.Type == mount.TypeBind { | ||
| // mkdir if bind source path does not exist | ||
| if _, err := os.Stat(m.Source); err != nil && os.IsNotExist(err) { | ||
| err = os.Mkdir(m.Source, 0755) |
There was a problem hiding this comment.
👎 doing so you create source on the CLI host, which might not be the dockerHost. Obviously this is what most people use for development, but this is wrong here. Need to understand how our bind configuration differs from docker/cli doing the same
Signed-off-by: aiordache <[email protected]>
Signed-off-by: aiordache <[email protected]>
|
This is likely caused if it's using the wrong API for the short-hand notation. The old "binds" API is used for the shorthand notation ( Here's a comparison: Shorthand: And the associated request that's made: Request; Details{
"AttachStderr": true,
"AttachStdin": false,
"AttachStdout": true,
"Cmd": null,
"Domainname": "",
"Entrypoint": null,
"Env": [],
"HostConfig": {
"AutoRemove": true,
"Binds": [
"/shorthand:/foo"
],
"BlkioDeviceReadBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceWriteIOps": null,
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"CapAdd": null,
"CapDrop": null,
"Cgroup": "",
"CgroupParent": "",
"ConsoleSize": [
0,
0
],
"ContainerIDFile": "",
"CpuCount": 0,
"CpuPercent": 0,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpuShares": 0,
"CpusetCpus": "",
"CpusetMems": "",
"DeviceCgroupRules": null,
"Devices": [],
"DiskQuota": 0,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IOMaximumBandwidth": 0,
"IOMaximumIOps": 0,
"IpcMode": "",
"Isolation": "",
"KernelMemory": 0,
"Links": null,
"LogConfig": {
"Config": {},
"Type": ""
},
"Memory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"NanoCpus": 0,
"NetworkMode": "default",
"OomKillDisable": false,
"OomScoreAdj": 0,
"PidMode": "",
"PidsLimit": 0,
"PortBindings": {},
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"RestartPolicy": {
"MaximumRetryCount": 0,
"Name": "no"
},
"SecurityOpt": null,
"ShmSize": 0,
"UTSMode": "",
"Ulimits": null,
"UsernsMode": "",
"VolumeDriver": "",
"VolumesFrom": null
},
"Hostname": "",
"Image": "hello-world",
"Labels": {},
"NetworkingConfig": {
"EndpointsConfig": {}
},
"OnBuild": null,
"OpenStdin": false,
"StdinOnce": false,
"Tty": false,
"User": "",
"Volumes": {},
"WorkingDir": ""
}And the "long form" ( docker run --rm --mount type=bind,src=/long,target=/foo hello-worldAnd associated request: Request: Details{
"AttachStderr": true,
"AttachStdin": false,
"AttachStdout": true,
"Cmd": null,
"Domainname": "",
"Entrypoint": null,
"Env": [],
"HostConfig": {
"AutoRemove": true,
"Binds": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceWriteIOps": null,
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"CapAdd": null,
"CapDrop": null,
"Cgroup": "",
"CgroupParent": "",
"ConsoleSize": [
0,
0
],
"ContainerIDFile": "",
"CpuCount": 0,
"CpuPercent": 0,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpuShares": 0,
"CpusetCpus": "",
"CpusetMems": "",
"DeviceCgroupRules": null,
"Devices": [],
"DiskQuota": 0,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IOMaximumBandwidth": 0,
"IOMaximumIOps": 0,
"IpcMode": "",
"Isolation": "",
"KernelMemory": 0,
"Links": null,
"LogConfig": {
"Config": {},
"Type": ""
},
"Memory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"Mounts": [
{
"Source": "/long",
"Target": "/foo",
"Type": "bind"
}
],
"NanoCpus": 0,
"NetworkMode": "default",
"OomKillDisable": false,
"OomScoreAdj": 0,
"PidMode": "",
"PidsLimit": 0,
"PortBindings": {},
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"RestartPolicy": {
"MaximumRetryCount": 0,
"Name": "no"
},
"SecurityOpt": null,
"ShmSize": 0,
"UTSMode": "",
"Ulimits": null,
"UsernsMode": "",
"VolumeDriver": "",
"VolumesFrom": null
},
"Hostname": "",
"Image": "hello-world",
"Labels": {},
"NetworkingConfig": {
"EndpointsConfig": {}
},
"OnBuild": null,
"OpenStdin": false,
"StdinOnce": false,
"Tty": false,
"User": "",
"Volumes": {},
"WorkingDir": ""
}Diff between both; git diff --no-index ./bind-shorthand.json ./bind-mounts.json
diff --git a/./bind-shorthand.json b/./bind-mounts.json
index d1d3311..003f482 100644
--- a/./bind-shorthand.json
+++ b/./bind-mounts.json
@@ -8,9 +8,7 @@
"Env": [],
"HostConfig": {
"AutoRemove": true,
- "Binds": [
- "/shorthand:/foo"
- ],
+ "Binds": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteBps": null,
@@ -57,6 +55,13 @@
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
+ "Mounts": [
+ {
+ "Source": "/long",
+ "Target": "/foo",
+ "Type": "bind"
+ }
+ ],
"NanoCpus": 0,
"NetworkMode": "default",
"OomKillDisable": false,So compose should switch between using one or the other API, depending on which form is used (long form / shorthand) |
|
@thaJeztah unfortunately we don't know which notation has been used by user after the compose file is parsed into compose-go types :'( |
|
Would it be an option to have an internal |
|
That could be an option indeed, but then the code don't just have to prepare |
|
For the "engine API" side, possibly it could take that option as well, but that would have to be discussed / accepted, and won't be in a release just yet, so wouldn't help in the short/medium term. |
|
@thaJeztah That's indeed sad the mount API does not expose this option that would make it a potential full replacement for the legacy bind API. But that's what we have ¯\(ツ)/¯ |
|
closed for #1604 |
Create a directory if a bind-mount source does not exist to align with docker-compose.
Closes #1543