Skip to content

fix: use valid bind addresses for remote Docker hosts - #8139

Merged
rfay merged 4 commits into
ddev:mainfrom
rfay:20260213_rfay_remote_docker
Feb 19, 2026
Merged

rfay merged 4 commits into
ddev:mainfrom
rfay:20260213_rfay_remote_docker

Conversation

@rfay

@rfay rfay commented Feb 13, 2026 •

Copy link
Copy Markdown
Member

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 on ddev 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

  • Adds IsRemoteDockerHost() in pkg/dockerutil/docker_manager.go 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 bind-address code paths (router.go, config.go, compose_yaml.go), overrides the bind IP to 0.0.0.0 when the Docker host is remote.
  • Hardcodes the Traefik monitor port to always bind to 127.0.0.1 in the router compose template, rather than using $dockerIP which could be a non-bindable remote IP.
  • Updates docs/content/users/topics/remote-docker.md with SSH-based Docker context setup (recommended), required DDEV configuration, and site access options.

For normal local Docker and DDEV hosting setups, IsRemoteDockerHost() returns false (the Docker IP is 127.0.0.1 from 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

  1. Set up a remote Docker host via SSH: docker context create remote --docker "host=ssh://user@remote-host" && docker context use remote
  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: switch back to default context, ddev start works as before

Automated Testing Overview

  • Updated TestTraefikMonitorPortAlwaysLocalhost to verify the monitor port binds to 127.0.0.1 explicitly rather than relying on GetDockerIP(), which makes the test correct for both local and remote Docker configurations.
  • IsRemoteDockerHost() returns false for 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-interfaces or --router-bind-all-interfaces for port binding to work — DDEV detects the remote host automatically. The Traefik monitor port now always binds to 127.0.0.1 regardless of Docker host configuration, which was already the intended behavior.

@rfay
rfay requested review from a team as code owners February 13, 2026 21:04
@github-actions

github-actions Bot commented Feb 13, 2026 •

Copy link
Copy Markdown

@rfay

rfay commented Feb 14, 2026

Copy link
Copy Markdown
Member Author

@rfay

rfay commented Feb 14, 2026

Copy link
Copy Markdown
Member Author

@rfay
rfay requested a review from stasadev February 16, 2026 04:34

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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::

ddev/pkg/ddevapp/ddevapp.go

Lines 1433 to 1437 in f4bf395

if dockerutil.IsDockerRootless() && !globalconfig.DdevGlobalConfig.NoBindMounts {
// See https://github.com/moby/moby/issues/45919
// See https://github.com/moby/moby/issues/2259
return fmt.Errorf("bind mounts can't be used with Docker Rootless.\nRun `ddev config global --no-bind-mounts` and try again")
}

@rfay
rfay force-pushed the 20260213_rfay_remote_docker branch from 4c86b22 to fd832d7 Compare February 16, 2026 17:32

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the ddev describe changes, I have a bit more 🙂

Comment on lines +223 to +227
// 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"
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We also show that bind-all-interfaces is used in ddev describe:

if app.BindAllInterfaces {
bindInfo = append(bindInfo, "bind-all-interfaces ENABLED")
}

To change:

-if app.BindAllInterfaces { 
+if app.BindAllInterfaces || dockerutil.IsRemoteDockerHost() {

@stasadev stasadev Feb 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And the same for router-bind-all-interfaces:

if globalconfig.DdevGlobalConfig.RouterBindAllInterfaces && !ddevapp.IsRouterDisabled(app) {
bindInfo = append(bindInfo, "router-bind-all-interfaces ENABLED")
}

-if globalconfig.DdevGlobalConfig.RouterBindAllInterfaces && !ddevapp.IsRouterDisabled(app) { 
+if (globalconfig.DdevGlobalConfig.RouterBindAllInterfaces || dockerutil.IsRemoteDockerHost()) && !ddevapp.IsRouterDisabled(app) {

Comment thread pkg/ddevapp/router.go
Comment on lines +203 to +207
// 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"
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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: tcp

And 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: tcp

It's actually the same thing, but a little inconsistent.

@rfay
rfay force-pushed the 20260213_rfay_remote_docker branch from fd832d7 to 82ec183 Compare February 17, 2026 21:30
@rfay
rfay requested a review from stasadev February 17, 2026 21:47

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me.

It works as expected with the Ubuntu VM - it has never been this easy to set up before.

rfay and others added 4 commits February 18, 2026 11:46
## 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]>
@rfay
rfay force-pushed the 20260213_rfay_remote_docker branch from 82ec183 to 0f0e5ac Compare February 18, 2026 18:47
@rfay
rfay merged commit cecc793 into ddev:main Feb 19, 2026
36 of 38 checks passed
@rfay
rfay deleted the 20260213_rfay_remote_docker branch February 19, 2026 00:30
Comment thread pkg/ddevapp/ddevapp.go
Comment on lines +1499 to +1502
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")
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

https://github.com/ddev/ddev-gitlab-ci/actions/runs/22178687155/job/64134000827

#   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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants