Skip to content

Commit e24d7fc

Browse files
iavigorpecovnik
authored andcommitted
fix(docker): anchor hostname extraction to leading "Name:" only
`docker info` emits both `Username: <user>` (under `Server:`) and `Name: <host>` near the bottom; the previous grep pattern `-i -e name:` caught both, so on hosts where docker stores credentials we ended up with `DOCKER_SERVER_NAME_HOST="<user> <host>"` after `cut + xargs` glued the two matches together. The Darwin `case` dispatch downstream then failed to recognise "Docker Desktop" / "Rancher Desktop", silently turning off the loop-hack workarounds. Anchor the grep to a leading-whitespace + literal `Name:` and take only the first match (`-m1`). Pre-existing on main, surfaced during P2b review by @coderabbitai. Assisted-by: Claude:claude-opus-4.7
1 parent 352f610 commit e24d7fc

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/functions/host/docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function docker_cli_prepare() {
222222
fi
223223
display_alert "Docker has buildx?" "${DOCKER_HAS_BUILDX}" "debug"
224224

225-
DOCKER_SERVER_NAME_HOST="$(grep -i -e "name:" <<< "${DOCKER_INFO}" | cut -d ":" -f 2 | xargs echo -n)"
225+
DOCKER_SERVER_NAME_HOST="$(grep -im1 -e "^ *Name:" <<< "${DOCKER_INFO}" | cut -d ":" -f 2 | xargs echo -n)"
226226
display_alert "Docker Server Hostname" "${DOCKER_SERVER_NAME_HOST}" "debug"
227227

228228
# Gymnastics: under Darwin, Docker Desktop and Rancher Desktop in dockerd mode behave differently.

0 commit comments

Comments
 (0)