I am having trouble with two-way folders with Docker.
defaultCfg.Mounts = append(ContainerHostConfig.Mounts, mount.Mount{
Type: mount.TypeVolume,
Source: fmt.Sprintf("/root%s", tmp),
Target: fmt.Sprintf("%s", tmp),
})
Source and target works when using bind (with CreateMountpoint being true on bind config), but on volume i have this error:
"failed to create container: Error response from daemon: create /root/tmp/metrics-60-1990068486: "/root/tmp/metrics-60-1990068486" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path"
"error is as descriptive as it can get"
"read the error"
"are you capable of reading"
If you intended to pass a host directory, use absolute path
isnt this absolute?
/root/tmp/metrics-60-1990068486
what is wrong?
2
Answers
Mounting a directory is called a bind mount, so you need to use
mount.TypeBind
instead ofmount.TypeVolume
.The error you are getting for
mount.TypeVolume
is due wrong name of the volume.Docker expects the
Source
to be the name of the volume, not an absolute path on the host filesystem.The error message is specifically complaining about the format of
/root/tmp/metrics-60-1990068486
being invalid for a volume name.If you want to use absolute path use
mount.TypeBind
instead.Docker Volume Documentation