fix: respect DOKKU_LIB_HOST_ROOT for storage bind mounts
When Dokku runs in Docker with a shared socket, create/chown still use DOKKU_LIB_ROOT inside the container, but Docker -v flags for storage:exec and deploy must use DOKKU_LIB_HOST_ROOT so the daemon mounts the host data volume instead of the real host's /var/lib/dokku. Closes #9126.
This commit is contained in:
8 files changed
+103
-3
No files matched your search
@@ -3,6 +3,7 @@ package storage
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -190,6 +191,26 @@ func GetStorageDirectory() string {
|
||||
return fmt.Sprintf("%s/data/storage", dokkuLibRoot)
|
||||
}
|
||||
|
||||
// HostPathForDocker rewrites a path under DOKKU_LIB_ROOT to the
|
||||
// DOKKU_LIB_HOST_ROOT view used by the host Docker daemon. Named
|
||||
// volumes and paths outside DOKKU_LIB_ROOT are returned unchanged.
|
||||
//
|
||||
// When Dokku runs in a container with a shared Docker socket, filesystem
|
||||
// operations must use DOKKU_LIB_ROOT (visible inside the Dokku container)
|
||||
// while Docker -v host paths must use DOKKU_LIB_HOST_ROOT (visible to the
|
||||
// daemon on the real host).
|
||||
func HostPathForDocker(path string) string {
|
||||
libRoot := common.GetenvWithDefault("DOKKU_LIB_ROOT", "/var/lib/dokku")
|
||||
libHost := os.Getenv("DOKKU_LIB_HOST_ROOT")
|
||||
if libHost == "" || libHost == libRoot {
|
||||
return path
|
||||
}
|
||||
if path == libRoot || strings.HasPrefix(path, libRoot+"/") {
|
||||
return libHost + strings.TrimPrefix(path, libRoot)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
// storageDirScriptNames lists the sudo helpers shipped in the plugin's bin
|
||||
// directory. Each one takes a storage entry basename and builds the path
|
||||
// under $DOKKU_LIB_ROOT/data/storage itself, so no caller can point them
|
||||
|
||||
Reference in new issue
Block a user