Skip to content

Commit ec509bf

Browse files
fix(clp-package): Detect Docker plugin directory from docker info and resolve it if it's a symlink (fixes #1554). (#1555)
Co-authored-by: kirkrodrigues <[email protected]>
1 parent b7c4763 commit ec509bf

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

components/package-template/src/sbin/.common-env.sh

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,28 @@ CLP_PWD_HOST="$(pwd 2>/dev/null || echo "")"
3131
export CLP_PWD_HOST
3232

3333
if [[ -z "${CLP_DOCKER_PLUGIN_DIR:-}" ]]; then
34-
for compose_plugin_dir in \
35-
"$HOME/.docker/cli-plugins" \
36-
"/mnt/wsl/docker-desktop/cli-tools/usr/local/lib/docker/cli-plugins" \
37-
"/usr/local/lib/docker/cli-plugins" \
38-
"/usr/libexec/docker/cli-plugins"; do
39-
40-
compose_plugin_path="$compose_plugin_dir/docker-compose"
41-
if [[ -f "$compose_plugin_path" ]]; then
42-
export CLP_DOCKER_PLUGIN_DIR="$compose_plugin_dir"
43-
break
44-
fi
45-
done
46-
if [[ -z "${CLP_DOCKER_PLUGIN_DIR:-}" ]]; then
47-
echo >&2 "Warning: Docker plugin directory not found;" \
48-
"Docker Compose may not work inside container."
34+
compose_plugin_path="$(docker info \
35+
--format '{{range .ClientInfo.Plugins}}{{if eq .Name "compose"}}{{.Path}}{{end}}{{end}}' \
36+
2>/dev/null)"
37+
38+
if [[ -z "$compose_plugin_path" || ! -f "$compose_plugin_path" ]]; then
39+
echo >&2 "Error: Docker Compose plugin not found via 'docker info'."
40+
return 1
41+
fi
42+
43+
resolved_plugin_path="$(readlink -f "$compose_plugin_path" 2>/dev/null || true)"
44+
if [[ -z "$resolved_plugin_path" ]]; then
45+
echo >&2 "Error: Failed to resolve Docker Compose plugin's real path."
46+
return 1
4947
fi
48+
49+
plugin_dir="$(dirname "$resolved_plugin_path")"
50+
if [[ -z "$plugin_dir" || "$plugin_dir" == "." || ! -d "$plugin_dir" ]]; then
51+
echo >&2 "Error: Failed to resolve Docker Compose plugin directory."
52+
return 1
53+
fi
54+
55+
export CLP_DOCKER_PLUGIN_DIR="$plugin_dir"
5056
fi
5157

5258
if [[ -z "${CLP_DOCKER_SOCK_PATH:-}" ]]; then

0 commit comments

Comments
 (0)