[BUG] `docker compose port` prints `:0` (exit 0) for a port the image exposes but the service does not publish

オープン 初心者向け
#14,522 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@ndeloof がすでに取り組んでいます。

2026年11月17日 から。

  • #14526 @ndeloof による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
docker, docker-compose, go
領域
backend, cli

調査の方向性

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時間
マージ済み PR(30日)
81

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

docker/compose のほかの issue

docker/compose の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。