Skip to content

Conversation

@emily-shen
Copy link
Contributor

@emily-shen emily-shen commented Jul 24, 2025

Fixes DEVX-2103.

Uses docker context ls to get the socket path that the docker daemon is listening on, without having to manually set it via config or an env var. This is he

Also checks the env var DOCKER_HOST (in addition to WRANGLER_DOCKER_HOST), which is a standard.

Also sets this properly in the vite plugin - we were previously only picking up the value set in the wrangler config.

This has unit tests but i've also tested this manually with the vite plugin/wrangler dev and colima (which listens at a special colima socket).


@emily-shen emily-shen requested review from a team as code owners July 24, 2025 16:00
@changeset-bot
Copy link

changeset-bot bot commented Jul 24, 2025

🦋 Changeset detected

Latest commit: 95c381a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@cloudflare/containers-shared Patch
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the v3-maintenance branch with your changes. Thank you for helping us keep Wrangler v3 supported!

Depending on your changes, running git rebase --onto v3-maintenance main emily/find-socket-docker-context might be a good starting point.

Notes:

  • your PR branch should be named v3-backport-10061
  • add the skip-v3-pr label to the current PR to stop this workflow from failing

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 24, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@10061

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@10061

miniflare

npm i https://pkg.pr.new/miniflare@10061

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@10061

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@10061

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@10061

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@10061

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@10061

wrangler

npm i https://pkg.pr.new/wrangler@10061

commit: 95c381a

@emily-shen emily-shen force-pushed the emily/find-socket-docker-context branch from 974cf07 to 7c37a6e Compare July 24, 2025 16:18
Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,

Added some inline comments

"wrangler": patch
---

feat: try to automatically get path of docker socket
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions:

Should "feat" imply a minor release?

Should "docker socket" be "container engine socket" (and use "container engine" below and in the other changeset rather than "docker" or "container tool")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our general rule of thumb apparently is features on experimental products get releases as patches, so i'll probably keep this as is.

good point on the docker specific language, i'll update the changesets


Currently, if your container tool isn't set up to listen at `unix:///var/run/docker.sock` (or isn't symlinked to that), then you have to manually set this via the `dev.containerEngine` field in your Wrangler config, or via the env vars `WRANGLER_DOCKER_HOST`. This change means that we will try and get the socket of the current context automatically. This should reduce the occurrence of opaque `internal error`s thrown by the runtime when the daemon is not listening at `unix:///var/run/docker.sock`.

You can still override this with `WRANGLER_DOCKER_HOST`, and we also now read `DOCKER_HOST` too.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can still override this with `WRANGLER_DOCKER_HOST`, and we also now read `DOCKER_HOST` too.
In addition to `WRANGLER_DOCKER_HOST`, `DOCKER_HOST` can now also be used to set the container engine socket address.

return resolve(stdout.trim());
});
});
export const runDockerCmdWithOutput = (dockerPath: string, args: string[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity what what this changed from async to sync? (not mentioned in the PR description).

Does it deserves a comment explaining why it should not be async?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the unstable_getMiniflareWorkerOptions api needs to use this to resolve the socket path, and that function is sync (and part of wranglers public api surface) so i wanted to avoid changing that.

return randomUUID().slice(0, 8);
}

type DockerContext = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is parsed from docker context ls, maybe add a comment.

Would it be worth adding some validations (zod or whatever) on top of JSON.parse

Copy link
Contributor Author

@emily-shen emily-shen Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't really want to add zod just to validate this one thing, if it fails we have a sensible fallback. i mean, i would love to add zod to validate very many things across wrangler, but this probably isn't the place to start 😅

but comment added though :)

Comment on lines +229 to +230
dockerPath,
containerEngine: options?.experimental?.containerEngine,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the diff on the first line is only moving code around.

Is the second line diff expected ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep - i don't want to try and get the socket path unless we are sure there are containers configured and enableContainers is true, but i don't think we have read the config yet here so we can't do that. instead i set it later on in configController.

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Jul 24, 2025
@emily-shen emily-shen added the skip-v3-pr Skip validation of presence of a v3 backport PR label Jul 25, 2025
@emily-shen emily-shen merged commit f8a80a8 into main Jul 25, 2025
49 of 55 checks passed
@emily-shen emily-shen deleted the emily/find-socket-docker-context branch July 25, 2025 13:39
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Jul 25, 2025
@emily-shen emily-shen mentioned this pull request Jul 28, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-v3-pr Skip validation of presence of a v3 backport PR

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants