Skip to content

Commit 4aa0be4

Browse files
committed
docker.Makefile: Use active context socket
The development and e2e containers hard-code /var/run/docker.sock, so rootless and other local contexts cannot expose their daemon socket. Resolve the active context's Docker endpoint and strip the unix scheme before using it as the bind source. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
1 parent dc99761 commit 4aa0be4

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

docker.Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
DOCKER_CLI_MOUNTS ?= -v "$(CURDIR)":/go/src/github.com/docker/cli
99
DOCKER_CLI_CONTAINER_NAME ?=
1010
DOCKER_CLI_GO_BUILD_CACHE ?= y
11+
DOCKER_SOCK ?= $(patsubst unix://%,%,$(shell docker context inspect --format '{{.Endpoints.docker.Host}}'))
1112

1213
# Sets the name of the company that produced the windows binary.
1314
PACKAGER_NAME ?=
@@ -62,7 +63,7 @@ dynbinary: ## build dynamically linked binary
6263
.PHONY: dev
6364
dev: build_docker_image ## start a build container in interactive mode for in-container development
6465
$(DOCKER_RUN) -it \
65-
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
66+
--mount type=bind,src=$(DOCKER_SOCK),dst=/var/run/docker.sock \
6667
$(DEV_DOCKER_IMAGE_NAME)
6768

6869
shell: dev ## alias for dev
@@ -134,14 +135,14 @@ test-e2e: test-e2e-local test-e2e-connhelper-ssh ## run all e2e tests
134135
test-e2e-local: build-e2e-image # run experimental e2e tests
135136
docker run --rm $(ENVVARS) \
136137
--mount type=bind,src=$(CURDIR)/build/coverage,dst=/tmp/coverage \
137-
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
138+
--mount type=bind,src=$(DOCKER_SOCK),dst=/var/run/docker.sock \
138139
$(E2E_IMAGE_NAME)
139140

140141
.PHONY: test-e2e-connhelper-ssh
141142
test-e2e-connhelper-ssh: build-e2e-image # run experimental SSH-connection helper e2e tests
142143
docker run --rm $(ENVVARS) -e TEST_CONNHELPER=ssh \
143144
--mount type=bind,src=$(CURDIR)/build/coverage,dst=/tmp/coverage \
144-
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
145+
--mount type=bind,src=$(DOCKER_SOCK),dst=/var/run/docker.sock \
145146
$(E2E_IMAGE_NAME)
146147

147148
.PHONY: help

0 commit comments

Comments
 (0)