From cb88c6ba10faecc7f3748c604bdde0471eab99a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 8 Jan 2026 12:20:47 +0100 Subject: [PATCH] daemon/volumes: More fs friendly image mount layer names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hash the container ID, mount source and destination together to form a layer name. This ensures the generated names are filesystem-friendly and don't exceed path length limits while maintaining uniqueness across different mount points and containers. Signed-off-by: Paweł Gronowski --- daemon/volumes.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/daemon/volumes.go b/daemon/volumes.go index a0c553d15d..48c072bf68 100644 --- a/daemon/volumes.go +++ b/daemon/volumes.go @@ -2,6 +2,7 @@ package daemon import ( "context" + "crypto/sha256" "encoding/hex" "maps" "os" @@ -258,10 +259,11 @@ func (daemon *Daemon) registerMountPoints(ctr *container.Container, defaultReadO 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. - // Hex encode the destination to create a safe, unique identifier - layerName := hex.EncodeToString([]byte(ctr.ID + ",src=" + mp.Source + ",dst=" + mp.Destination)) + // We hash it so that the snapshot name is friendly to the underlying filesystem and doesn't exceed path length limits. + destHash := sha256.Sum256([]byte(ctr.ID + "-src=" + mp.Source + "-dst=" + mp.Destination)) + layerName := hex.EncodeToString(destHash[:]) layer, err := daemon.imageService.CreateLayerFromImage(img, layerName, rwLayerOpts) if err != nil { return err