Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[BUG] `start -p <name>` treats an optional (`required: false`) dependency as required

Đang mở
#14,311 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

  • #14312 của @htoyoda18 — đã đóng, không merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
22/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
go
Lĩnh vực
cli

Hướng nghiên cứu

The required flag is dropped when the project is rebuilt from container labels: pkg/compose/create.go writes the com.docker.compose.depends_on label without it, and projectFromName in pkg/compose/compose.go hard-codes required := true when reading it back. Compare with getProjectWithResources in down.go, which forces Required = false, and check whether start can use the same approach. Done when docker compose -p <name> start starts web after the optional init fails, matching the file-based behaviour; a linked pull request (#14312) already exists, so coordinate with it before starting.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Description

When a service has an optional dependency (depends_on.<svc>.required: false) that fails, docker compose start behaves differently depending on whether the compose file is read:

  • docker compose start (with the compose file): warns optional dependency "init" didn't complete successfully and starts web.
  • docker compose -p <name> start (no -f): fails with service "init" didn't complete successfully: exit 1, and web is not started.

Expected: -p <name> start treats the dependency as optional too, as it does when the file is read.

Steps To Reproduce
services:
  web:
    image: alpine:3.21
    command: sleep infinity
    depends_on:
      init:
        condition: service_completed_successfully
        required: false
  init:
    image: alpine:3.21
    command: sh -c "exit 1"
$ docker compose -p optdep up -d
$ docker compose -p optdep stop
$ docker compose -f compose.yaml -p optdep start   # exit 0, web running
$ docker compose -p optdep stop
$ docker compose -p optdep start
 Container optdep-init-1 Error service "init" didn't complete successfully: exit 1
service "init" didn't complete successfully: exit 1
$ echo $?
1
$ docker compose -p optdep ps -a --format '{{.Service}} {{.State}}'
init exited
web exited
Compose Version
Docker Compose version v5.6.0-24-g4e1cd3f4e (built from main at 4e1cd3f4e)
Docker Environment
Server Version: 29.1.3
Operating System: Docker Desktop
OSType/Architecture: linux/aarch64
Anything else?

With -p and no -f, the project is rebuilt from container labels (projectFromName), and required is lost on the way:

  • pkg/compose/create.go writes com.docker.compose.depends_on as service:condition:restart only. The label on web above is init:service_completed_successfully:false.
  • projectFromName in pkg/compose/compose.go reads it back with required := true hard-coded.
  • down/stop/restart already compensate for this: getProjectWithResources in down.go forces Required = false. start doesn't, so -p alone works for restart but not for start.

A possible fix: store required as a 4th field of the label and default to true when it is missing (labels written by older versions). #14081 lot 2 (#14296) moves compose start, including the projectFromName path, onto the plan engine, but it doesn't touch this label, so the bug would remain. Happy to send a PR if this direction is fine.

Ngôn ngữ chính
Go
Star
38.4k
Fork
5.9k
Merge trung bình
2 ngày 7 giờ
Pull request đã merge (30 ngày)
60

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của docker/compose

Tất cả issue của docker/compose

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.