mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #51827 from vvoland/fix-image-mount
daemon/volumes: More fs friendly image mount layer names
This commit is contained in:
@@ -2,6 +2,7 @@ package daemon
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"maps"
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
@@ -258,10 +259,11 @@ func (daemon *Daemon) registerMountPoints(ctr *container.Container, defaultReadO
|
|||||||
StorageOpt: ctr.HostConfig.StorageOpt,
|
StorageOpt: ctr.HostConfig.StorageOpt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include the destination in the layer name to make it unique for each mount point and container.
|
// Hash the source and destination to create a safe, unique identifier for each mount point and container.
|
||||||
// This makes sure that the same image can be mounted multiple times with different destinations.
|
// This makes sure that the same image can be mounted multiple times with different destinations.
|
||||||
// Hex encode the destination to create a safe, unique identifier
|
// We hash it so that the snapshot name is friendly to the underlying filesystem and doesn't exceed path length limits.
|
||||||
layerName := hex.EncodeToString([]byte(ctr.ID + ",src=" + mp.Source + ",dst=" + mp.Destination))
|
destHash := sha256.Sum256([]byte(ctr.ID + "-src=" + mp.Source + "-dst=" + mp.Destination))
|
||||||
|
layerName := hex.EncodeToString(destHash[:])
|
||||||
layer, err := daemon.imageService.CreateLayerFromImage(img, layerName, rwLayerOpts)
|
layer, err := daemon.imageService.CreateLayerFromImage(img, layerName, rwLayerOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user