[BUG] `docker compose port` prints `:0` (exit 0) for a port the image exposes but the service does not publish
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
Direzione di ricerca
Inizia da internal/inspect/port.go, in Ports, poi leggi internal/inspect/inspect_test.go e i test esistenti sulla gestione delle porte. Riproduci il caso della porta esposta ma non pubblicata e verifica come docker compose port gestisce i publisher con PublishedPort == 0. Il lavoro è completato quando la porta richiesta genera un errore e la modalità elenco la omette, mentre le porte pubblicate e il comportamento di ps restano invariati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
"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.
- Lingua principale
- Go
- Stelle
- 38.9k
- Fork
- 6k
- Merge medio
- 2g 22h
- PR unite (30g)
- 81
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di docker/compose
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
docker/compose#14435 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] deploy.restart_policy without condition drops the restart policyForse di nuovo libera @akshat-lakhera l’ha presa 25 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
docker/compose#14383 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] up: an optional (required: false) service_healthy dependent is not started when a required dependent shares the failing waitForse già presa @ndeloof l’ha presa 2 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 58/100
docker/compose#14507 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] Negative replica count in scale flags (docker compose scale / --scale) is accepted without validationForse già presa @arsalanyavari l’ha presa 8 giorni fa. Apertakind/bug status/approved
Difficoltà 2/5 1-3 ore Idoneità per principianti 30/100
I maintainer di solito rispondono entro 1 giorno
-
[BUG] pre_stop hooks are skipped when up or scale stops a containerForse già presa @htoyoda18 l’ha presa 11 giorni fa. Apertakind/bug status/approved
Difficoltà 4/5 3-5 giorni Idoneità per principianti 53/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di docker/compose
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
fluxcd/notification-controller#1441 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
OneBusAway/maglev#2145 ·
I maintainer di solito rispondono entro 2 giorni
-
priority/medium status/ready type/chore
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
discobox-ai/discobox#1357 ·
I maintainer di solito rispondono entro 1 giorno
-
TestPseudoLocaleRemote fails now and then: it types the code before the laptop asks for itForse già presa @fzn0x l’ha presa oggi. Apertabug priority: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
edit_file diff rendering panics on invalid UTF-8 textForse già presa @TDnorthgarden l’ha presa oggi. Apertaarea/tui
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
docker/docker-agent#4955 ·
I maintainer di solito rispondono entro 1 giorno