Skip to content

Commit e4c9762

Browse files
committed
build: docker: detect & export DOCKER_HOST from current docker context
- Some Docker-in-VM solutions (like Docker Desktop, colima, etc) set a non-default docker context pointing to the correct socket - Seems LinuxKit fumbles detecting this and ends up silently failing all local-Docker-daemon cache hits - that is fine for CI, where all images are (beforehand) pushed to the registry (and thus LK ends up pulling from remote), but not during local development - reported to upstream LinuxKit: linuxkit/linuxkit#4092 Signed-off-by: Ricardo Pardini <[email protected]>
1 parent aa9c6a0 commit e4c9762

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

bash/docker.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
function check_docker_daemon_for_sanity() {
2+
# LinuxKit is a bit confused about `docker context list` when you're using a non-default context.
3+
# Let's obtain the currect socket from the current context and explicitly export it.
4+
# This allows working on machines with Docker Desktop, colima, and other run-linux-in-a-VM solutions.
5+
declare current_context_docker_socket="" current_docker_context_name=""
6+
current_docker_context_name="$(docker context show)"
7+
current_context_docker_socket="$(docker context inspect "${current_docker_context_name}" | jq -r '.[0].Endpoints.docker.Host')"
8+
log info "Current Docker context ('${current_docker_context_name}') socket: '${current_context_docker_socket}'"
9+
10+
log debug "Setting DOCKER_HOST to '${current_context_docker_socket}'"
11+
export DOCKER_HOST="${current_context_docker_socket}"
12+
213
# Shenanigans to go around error control & capture output in the same effort, 'docker info' is slow.
314
declare docker_info docker_buildx_version
415
docker_info="$({ docker info 2> /dev/null && echo "DOCKER_INFO_OK"; } || true)"

0 commit comments

Comments
 (0)