[BUG] `docker compose port` prints `:0` (exit 0) for a port the image exposes but the service does not publish
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
调研方向
从 internal/inspect/port.go 中的 Ports 开始,然后阅读 internal/inspect/inspect_test.go 和现有的端口处理测试。复现已暴露但未发布的端口场景,并检查 docker compose port 如何处理 PublishedPort == 0 的 publisher。完成标准是:请求的端口报错,列表模式将其省略,同时已发布的端口和 ps 的行为保持不变。
由索引模型根据 Issue 内容生成。
描述
"This issue was filed by an AI agent on a human's behalf. The human submitter may not have independently verified the report."
Description
docker compose port SERVICE PRIVATE_PORT is documented to "print the public port for a specific mapping". When the private port is only exposed (e.g. an image EXPOSE) and has no host binding, it prints :0 and exits 0 instead of failing. In list mode (docker compose port SERVICE) the same port shows up as 6379/tcp -> :0.
docker port on the same container prints no public port '6379' published for ... with exit code 1, and lists nothing in list mode. #10039 (fixing #10010) already turned the "port not found → :0" case into an error; the exposed-but-unpublished case still goes through, because the container listing reports exposed ports with PublicPort: 0 and internal/inspect/port.go keeps them.
Real-world impact: a script doing ADDR=$(docker compose port db 6379) for a redis/postgres service that does not publish its port gets :0 and exit 0, and fails later with a confusing connection error.
Steps To Reproduce
services:
web:
image: nginx:alpine
ports:
- "8080:80"
db:
image: redis:alpine # EXPOSE 6379, not published
$ docker compose -p portrepro up -d
$ docker compose -p portrepro port web 80 # control
0.0.0.0:8080 # rc=0
$ docker compose -p portrepro port db 6379
:0 # rc=0
$ docker compose -p portrepro port db
6379/tcp -> :0 # rc=0
$ docker port portrepro-db-1 6379
no public port '6379' published for portrepro-db-1 # rc=1
$ docker port portrepro-db-1
# (nothing), rc=0
Expected: port db 6379 fails like docker port does (with the existing "no port 6379/tcp for container ..." error), and list mode only lists published ports.
Compose Version
main @ ed25575984c8 (built locally: go build -o bin/docker-compose ./cmd)
Docker Environment
Server Version: 29.5.2 (colima VM, Ubuntu 24.04 aarch64), client on macOS arm64
Anything else?
Suggested fix: skip publishers with PublishedPort == 0 in internal/inspect/port.go (Ports). containerPublishers is shared with ps, which should keep showing 6379/tcp like docker ps, so it is left unchanged. With that change: port db 6379 → no port 6379/tcp for container portrepro-db-1: 6379/tcp, rc=1; port db → empty; port web 80 / port web unchanged. A unit test in internal/inspect/inspect_test.go (TestPortsSkipsExposedButUnpublishedPorts) fails on main and passes with the change. Happy to open the PR once this is triaged.
AI disclosure: Claude Code (Anthropic) found the issue, ran the reproduction, and drafted this report, the patch and the test.
- 主要语言
- Go
- 星标
- 38.9k
- 派生
- 6k
- 平均合并
- 2 天 22 小时
- 30 天内合并 PR
- 81
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
docker/compose 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
docker/compose#14435 · 2 条评论 ·
维护者通常 1 天内回复
-
[BUG] deploy.restart_policy without condition drops the restart policy可能重新可做 @akshat-lakhera 于 25 天前认领,目前没有进行中的 PR。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
docker/compose#14383 · 3 条评论 ·
维护者通常 1 天内回复
-
[BUG] up: an optional (required: false) service_healthy dependent is not started when a required dependent shares the failing wait可能已有人在做 @ndeloof 于 2 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 58/100
docker/compose#14507 · 2 条评论 ·
维护者通常 1 天内回复
-
[BUG] Negative replica count in scale flags (docker compose scale / --scale) is accepted without validation可能已有人在做 @arsalanyavari 于 8 天前认领。 未关闭kind/bug status/approved
难度 2/5 1-3 小时 新手友好度 30/100
维护者通常 1 天内回复
-
[BUG] pre_stop hooks are skipped when up or scale stops a container可能已有人在做 @htoyoda18 于 11 天前认领。 未关闭kind/bug status/approved
难度 4/5 3-5 天 新手友好度 53/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
IBM-Cloud/terraform-provider-ibm#7115 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 86/100
fluxcd/notification-controller#1441 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 66/100
volcengine/volcengine-go-sdk#163 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
OneBusAway/maglev#2145 ·
维护者通常 2 天内回复
-
priority/medium status/ready type/chore
难度 2/5 1-3 小时 新手友好度 84/100
discobox-ai/discobox#1357 ·
维护者通常 1 天内回复