Skip to content

fix(docker/container): report assigned host ports, support extra hosts, stop disconnecting foreign networks - #1398

Merged
Mkassabov merged 1 commit into
mainfrom
fix/docker-container-ports-hosts-networks
Aug 29, 2026
Merged

fix(docker/container): report assigned host ports, support extra hosts, stop disconnecting foreign networks#1398
Mkassabov merged 1 commit into
mainfrom
fix/docker-container-ports-hosts-networks

Conversation

@Mkassabov

Copy link
Copy Markdown
Contributor

Three independent Docker.Container bugs, each with a regression test that fails without its fix.

Assigned host port reported as 0 (#1388)

external: 0 means "any free host port". The create arg asked for host port 0 literally, and toContainerAttributes then overlaid the requested bindings on top of the assigned ones:

-p: news.ports?.map((port) => `${port.external}:${port.internal}/${port.protocol ?? "tcp"}`)
+// `-p 80/tcp` (random publish), not `-p 0:80/tcp`
+p: news.ports?.map((port) => isRandomHostPort(port.external) ? target : `${port.external}:${target}`)

-ports: { ...info.NetworkSettings.Ports, ...info.HostConfig.PortBindings }  // request wins
+ports: toPortAttributes(info)                                             // assignment wins

The request stays the fallback — a created-but-not-started container has empty NetworkSettings.Ports.

Before: expected 0 to be greater than 0.

No way to set extra hosts (#1387)

Added extraHosts?: string[], forwarded as --add-host:

Docker.Container("api", {
  image: "ghcr.io/acme/api:latest",
  extraHosts: ["host.docker.internal:host-gateway"],
});

Before: expected null to equal ArrayContaining [ "host.docker.internal:host-gateway" ].

Reconciliation disconnected foreign networks (#1386)

Removals were derived from every live network, so anything alchemy had not connected was torn off — including Docker's default bridge. They now come from olds.networks, the only record of what alchemy itself attached; the live container cannot say who connected a network.

Before, after dropping one managed network, the container was left with no networks at all: expected [ ] to contain "alchemy-test-foreign-network".

…s, stop disconnecting foreign networks

Three independent `Docker.Container` bugs.

`external: 0` means "any free host port", but the create arg asked Docker for
host port 0 literally, and `toContainerAttributes` then overlaid the *requested*
`HostConfig.PortBindings` on top of the *assigned* `NetworkSettings.Ports`, so
the attribute read back as 0. Random publishes now use Docker's bare
`internal/protocol` form, and the assignment wins over the request (the request
stays the fallback for a created-but-not-started container). Fixes #1388.

`extraHosts` had no way in: no prop, no `--add-host` create arg, so a container
could not be given a `host-gateway` mapping. Fixes #1387.

Reconciliation derived network removals from every live network, so any network
alchemy had not connected — Docker's default `bridge`, or one attached by a
user, a compose file, or another tool — was torn off. Removals now come from
`olds.networks`, the only record of what alchemy itself attached. Fixes #1386.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@alchemy-version-bot

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

Alchemy

alchemy

bun add https://pkg.ing/alchemy/e2ee40e

@alchemy.run/better-auth

bun add https://pkg.ing/@alchemy.run/better-auth/e2ee40e

@alchemy.run/cloudflare-runtime

bun add https://pkg.ing/@alchemy.run/cloudflare-runtime/e2ee40e

@alchemy.run/frontend-frameworks

bun add https://pkg.ing/@alchemy.run/frontend-frameworks/e2ee40e

@alchemy.run/node-utils

bun add https://pkg.ing/@alchemy.run/node-utils/e2ee40e

@alchemy.run/pr-package

bun add https://pkg.ing/@alchemy.run/pr-package/e2ee40e

@alchemy.run/floci

bun add https://pkg.ing/@alchemy.run/floci/e2ee40e

Distilled

@distilled.cloud/core

bun add https://pkg.ing/@distilled.cloud/core/db3a1b5

@distilled.cloud/aws

bun add https://pkg.ing/@distilled.cloud/aws/db3a1b5

@distilled.cloud/axiom

bun add https://pkg.ing/@distilled.cloud/axiom/db3a1b5

@distilled.cloud/cloudflare

bun add https://pkg.ing/@distilled.cloud/cloudflare/db3a1b5

@distilled.cloud/hetzner

bun add https://pkg.ing/@distilled.cloud/hetzner/db3a1b5

@distilled.cloud/neon

bun add https://pkg.ing/@distilled.cloud/neon/db3a1b5

@distilled.cloud/planetscale

bun add https://pkg.ing/@distilled.cloud/planetscale/db3a1b5

@Mkassabov
Mkassabov merged commit ffb4299 into main Aug 29, 2026
7 checks passed
@Mkassabov
Mkassabov deleted the fix/docker-container-ports-hosts-networks branch August 29, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant