Repository navigation
fix: use valid bind addresses for remote Docker hosts - #8139
Conversation
|
Download the artifacts for this pull request:
See Testing a PR. |
|
Lima timing out after 4 hours, https://buildkite.com/ddev/macos-lima/builds/5709#019c58d2-475c-4bd6-9551-0178722231a6 tb-macos-arm64-5 TestCustomGlobalConfig |
|
Orbstack timed out after 4 hours, TestCustomGlobalConfig, https://buildkite.com/ddev/macos-orbstack/builds/6535#019c5aa0-23de-4447-a33e-c6135b68e0fc |
|
|
||
| The DDEV site will *not* be at `127.0.0.1`. You have two options: | ||
|
|
||
| * **SSH tunnel**: Forward DDEV ports (like 8080, 8443) from the remote host to your local machine. This lets you access sites at `localhost:<port>` without exposing ports on the remote host. |
There was a problem hiding this comment.
@rfay I use this "https://gist.github.com/svicervlad/47c4c46233f580b9cd17f5016802a3d0" bash script for SSH tunneling that auto-detects the remote host from the active Docker context. Would be cool if something like this could be adapted into DDEV's Go code.
There was a problem hiding this comment.
That's a cool approach. This is such a niche situation that I don't want to add code for it, but it's a great place to systematize it and explain it in a ddev.com post. You may want to make an add-on or other testable systematic approach to deliver this configuration as well.
stasadev
left a comment
There was a problem hiding this comment.
Looks good to me, and this setup is easier than what we already.
It's already good enough, but while we are here, I would like to reuse GetDockerIP() in the ddev describe, it's never 127.0.0.1 with remote Docker:
│ InDocker -> Host: │
│ - web:80 -> 127.0.0.1:32778 │
│ - web:443 -> 127.0.0.1:32779 │
│ - web:8025 -> 127.0.0.1:32780 |
|
|
||
| ### Required DDEV Configuration | ||
|
|
||
| * **Disable bind mounts**: Bind mounts cannot work with a remote Docker setup, so you must use `ddev config global --no-bind-mounts`. This causes DDEV to push needed information to and from the remote Docker instance when needed. This also automatically turns on Mutagen caching. |
There was a problem hiding this comment.
I didn't disable bind mounts, which resulted in a 404 as expected, but it may be more obvious if we also have an explicit check on ddev start, similar to what I did with Docker Rootless::
Lines 1433 to 1437 in f4bf395
4c86b22 to
fd832d7
Compare
stasadev
left a comment
There was a problem hiding this comment.
Thanks for the ddev describe changes, I have a bit more 🙂
| // On remote Docker hosts, the Docker IP (e.g. a cloud provider's public IP) | ||
| // is not a valid bind address on the Docker host itself, so bind to all interfaces. | ||
| if dockerutil.IsRemoteDockerHost() { | ||
| bindIP = "0.0.0.0" | ||
| } |
There was a problem hiding this comment.
We also show that bind-all-interfaces is used in ddev describe:
Lines 251 to 253 in f4bf395
To change:
-if app.BindAllInterfaces {
+if app.BindAllInterfaces || dockerutil.IsRemoteDockerHost() {There was a problem hiding this comment.
And the same for router-bind-all-interfaces:
Lines 254 to 256 in f4bf395
-if globalconfig.DdevGlobalConfig.RouterBindAllInterfaces && !ddevapp.IsRouterDisabled(app) {
+if (globalconfig.DdevGlobalConfig.RouterBindAllInterfaces || dockerutil.IsRemoteDockerHost()) && !ddevapp.IsRouterDisabled(app) {| // On remote Docker hosts, the Docker IP (e.g. a cloud provider's public IP) | ||
| // is not a valid bind address on the Docker host itself, so bind to all interfaces. | ||
| if dockerutil.IsRemoteDockerHost() { | ||
| dockerIP = "0.0.0.0" | ||
| } |
There was a problem hiding this comment.
The same can be done several lines below by reusing router_bind_all_interfaces:
-"router_bind_all_interfaces": globalconfig.DdevGlobalConfig.RouterBindAllInterfaces,
+"router_bind_all_interfaces": globalconfig.DdevGlobalConfig.RouterBindAllInterfaces || dockerutil.IsRemoteDockerHost(),I mention this only because when you set router-bind-all-interfaces, the ~/.ddev/.router-compose-full.yaml has:
ports:
- mode: ingress
target: 443
published: "443"
protocol: tcpAnd in this PR when you don't set router-bind-all-interfaces:
ports:
- mode: ingress
host_ip: 0.0.0.0
target: 443
published: "443"
protocol: tcpIt's actually the same thing, but a little inconsistent.
fd832d7 to
82ec183
Compare
stasadev
left a comment
There was a problem hiding this comment.
Looks good to me.
It works as expected with the Ubuntu VM - it has never been this easy to set up before.
## The Issue When using a remote Docker context (e.g., via SSH or TCP), `GetDockerIP()` returns the remote host's IP address (such as a cloud provider's public IP). This IP is not a valid bind address on the Docker host itself (e.g., on AWS the public IP is NAT'd and not assigned to any interface), causing "cannot assign requested address" errors for the router and all project containers. ## How This PR Solves The Issue - Add `IsRemoteDockerHost()` to detect when Docker is running on a non-local machine by checking whether the Docker IP is loopback or assigned to a local network interface. - In all three places where `GetDockerIP()` is used as a bind address (router compose generation, project compose template, project compose post-processing), override to `0.0.0.0` when the Docker host is remote. - Hardcode the Traefik monitor port to always bind to `127.0.0.1` for security, rather than using `$dockerIP` which could be a remote IP. - Update remote Docker documentation with SSH-based context setup, required DDEV configuration, and access options. ## Manual Testing Instructions 1. Set up a remote Docker host (e.g., `docker context create remote --docker "host=ssh://user@remote-host"`) 2. `ddev config global --no-bind-mounts` 3. `ddev config --project-type=php` 4. `ddev start` should succeed without "cannot assign requested address" errors 5. Verify normal local Docker usage is unaffected ## Automated Testing Overview - Updated `TestTraefikMonitorPortAlwaysLocalhost` to verify the monitor port binds to `127.0.0.1` explicitly rather than relying on `GetDockerIP()`. - `IsRemoteDockerHost()` returns false for all local Docker configurations (loopback, local interface IPs), ensuring no behavior change for existing users. ## Release/Deployment Notes No breaking changes. Remote Docker users no longer need to manually set `--bind-all-interfaces` or `--router-bind-all-interfaces` for port binding to work. The Traefik monitor port now always binds to `127.0.0.1` regardless of Docker host configuration. Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Use GetDockerIP() in `ddev describe` instead of hardcoded 127.0.0.1 - Remove bind-all-interfaces requirement from docs (now automatic) - Add explicit check on `ddev start` for no-bind-mounts with remote Docker Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Show bind-all-interfaces status in `ddev describe` for remote Docker - Set router_bind_all_interfaces for remote Docker hosts - Remove redundant conditional block in compose_yaml.go Co-Authored-By: Claude Opus 4.6 <[email protected]>
82ec183 to
0f0e5ac
Compare
| if dockerutil.IsRemoteDockerHost() && !globalconfig.DdevGlobalConfig.NoBindMounts { | ||
| return fmt.Errorf("bind mounts can't be used with a remote Docker host.\nRun `ddev config global --no-bind-mounts` and try again") | ||
| } | ||
|
|
There was a problem hiding this comment.
# Failed to start tryddevproject-6800: bind mounts can't be used with a remote Docker host.
# Run `ddev config global --no-bind-mounts` and try again
This change broke the ddev-gitlab-ci test. We used to use no-bind-mounts there, but then removed it, because there's a way to bypass bind-mounts:
I'm going to remove this condition.
The Issue
When using a remote Docker context (SSH or TCP),
GetDockerIP()returns the remote host's IP address (e.g., an AWS public IP). This IP is not a valid bind address on the Docker host itself because cloud providers use NAT — the public IP is not assigned to any network interface on the instance. This causes "cannot assign requested address" errors for the router and all project containers onddev start.The problem affects three separate code paths where
GetDockerIP()is used as a Docker port bind address: router compose generation, project compose template rendering, and project compose post-processing.How This PR Solves The Issue
IsRemoteDockerHost()inpkg/dockerutil/docker_manager.goto detect when Docker is running on a non-local machine by checking whether the Docker IP is loopback or assigned to a local network interface.router.go,config.go,compose_yaml.go), overrides the bind IP to0.0.0.0when the Docker host is remote.127.0.0.1in the router compose template, rather than using$dockerIPwhich could be a non-bindable remote IP.docs/content/users/topics/remote-docker.mdwith SSH-based Docker context setup (recommended), required DDEV configuration, and site access options.For normal local Docker and DDEV hosting setups,
IsRemoteDockerHost()returnsfalse(the Docker IP is127.0.0.1from the unix socket), so there is no behavior change.Manual Testing Instructions
Updated doc rendered at https://github.com/rfay/ddev/blob/20260213_rfay_remote_docker/docs/content/users/topics/remote-docker.md
docker context create remote --docker "host=ssh://user@remote-host" && docker context use remoteddev config global --no-bind-mountsddev config --project-type=phpddev start— should succeed without "cannot assign requested address" errorsddev startworks as beforeAutomated Testing Overview
TestTraefikMonitorPortAlwaysLocalhostto verify the monitor port binds to127.0.0.1explicitly rather than relying onGetDockerIP(), which makes the test correct for both local and remote Docker configurations.IsRemoteDockerHost()returnsfalsefor all local Docker configurations (loopback, local interface IPs), so existing tests are unaffected.Release/Deployment Notes
No breaking changes. Remote Docker users no longer need to manually set
--bind-all-interfacesor--router-bind-all-interfacesfor port binding to work — DDEV detects the remote host automatically. The Traefik monitor port now always binds to127.0.0.1regardless of Docker host configuration, which was already the intended behavior.