mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Skip existing volumes in volumes-from
Removes the error when a container already has a volume that would otherwise be created by `Config.VolumesFrom`. Allows restarting containers with a `Config.VolumesFrom` set.
This commit is contained in:
parent
3bd73a9633
commit
57b49efc98
2 changed files with 12 additions and 4 deletions
10
container.go
10
container.go
|
@ -587,7 +587,7 @@ func (container *Container) Start(hostConfig *HostConfig) error {
|
|||
}
|
||||
for volPath, id := range c.Volumes {
|
||||
if _, exists := container.Volumes[volPath]; exists {
|
||||
return fmt.Errorf("The requested volume %s overlap one of the volume of the container %s", volPath, c.ID)
|
||||
continue
|
||||
}
|
||||
if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil {
|
||||
return nil
|
||||
|
@ -602,10 +602,12 @@ func (container *Container) Start(hostConfig *HostConfig) error {
|
|||
// Create the requested volumes if they don't exist
|
||||
for volPath := range container.Config.Volumes {
|
||||
volPath = path.Clean(volPath)
|
||||
// If an external bind is defined for this volume, use that as a source
|
||||
// Skip existing volumes
|
||||
if _, exists := container.Volumes[volPath]; exists {
|
||||
// Skip existing mounts
|
||||
} else if bindMap, exists := binds[volPath]; exists {
|
||||
continue
|
||||
}
|
||||
// If an external bind is defined for this volume, use that as a source
|
||||
if bindMap, exists := binds[volPath]; exists {
|
||||
container.Volumes[volPath] = bindMap.SrcPath
|
||||
if strings.ToLower(bindMap.Mode) == "rw" {
|
||||
container.VolumesRW[volPath] = true
|
||||
|
|
|
@ -1333,6 +1333,12 @@ func TestVolumesFromWithVolumes(t *testing.T) {
|
|||
if container.Volumes["/test"] != container2.Volumes["/test"] {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
// Ensure it restarts successfully
|
||||
_, err = container2.Output()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOnlyLoopbackExistsWhenUsingDisableNetworkOption(t *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue