Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ example-provider: ## build example provider for e2e tests
mocks:
mockgen --version >/dev/null 2>&1 || go install go.uber.org/mock/mockgen@v0.4.0
mockgen -destination pkg/mocks/mock_docker_cli.go -package mocks github.com/docker/cli/cli/command Cli
mockgen -destination pkg/mocks/mock_docker_api.go -package mocks github.com/docker/docker/client APIClient
mockgen -destination pkg/mocks/mock_docker_api.go -package mocks github.com/moby/moby/client APIClient
mockgen -destination pkg/mocks/mock_docker_compose_api.go -package mocks -source=./pkg/api/api.go Service

.PHONY: e2e
Expand Down
4 changes: 2 additions & 2 deletions cmd/compose/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (

"github.com/distribution/reference"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/go-units"
"github.com/moby/moby/api/types/image"
"github.com/moby/moby/client/pkg/stringid"
"github.com/spf13/cobra"

"github.com/docker/compose/v2/cmd/formatter"
Expand Down
4 changes: 2 additions & 2 deletions cmd/compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,17 @@ func resolveImageDigests(ctx context.Context, dockerCli command.Cli, model map[s
func formatModel(model map[string]any, format string) (content []byte, err error) {
switch format {
case "json":
content, err = json.MarshalIndent(model, "", " ")
return json.MarshalIndent(model, "", " ")
case "yaml":
buf := bytes.NewBuffer([]byte{})
encoder := yaml.NewEncoder(buf)
encoder.SetIndent(2)
err = encoder.Encode(model)
content = buf.Bytes()
return content, err
default:
return nil, fmt.Errorf("unsupported format %q", format)
}
return
}

func runServices(ctx context.Context, dockerCli command.Cli, opts configOptions) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/compose/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (

"github.com/containerd/platforms"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/go-units"
"github.com/moby/moby/client/pkg/stringid"
"github.com/spf13/cobra"

"github.com/docker/compose/v2/cmd/formatter"
Expand Down
37 changes: 30 additions & 7 deletions cmd/compose/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ package compose

import (
"context"
"errors"
"fmt"
"io"
"regexp"
"strings"

"github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/cmd/formatter"
"github.com/moby/moby/client"

"github.com/docker/cli/opts"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -61,25 +64,45 @@ var acceptedListFilters = map[string]bool{
"name": true,
}

// match returns true if any of the values at key match the source string
func match(filters client.Filters, field, source string) bool {
if f, ok := filters[field]; ok && f[source] {
return true
}

fieldValues := filters[field]
for name2match := range fieldValues {
isMatch, err := regexp.MatchString(name2match, source)
if err != nil {
continue
}
if isMatch {
return true
}
}
return false
}

func runList(ctx context.Context, dockerCli command.Cli, backend api.Service, lsOpts lsOptions) error {
filters := lsOpts.Filter.Value()
err := filters.Validate(acceptedListFilters)
if err != nil {
return err

for filter := range filters {
if _, ok := acceptedListFilters[filter]; !ok {
return errors.New("invalid filter '" + filter + "'")
}
}

stackList, err := backend.List(ctx, api.ListOptions{All: lsOpts.All})
if err != nil {
return err
}

if filters.Len() > 0 {
if len(filters) > 0 {
var filtered []api.Stack
for _, s := range stackList {
if filters.Contains("name") && !filters.Match("name", s.Name) {
continue
if match(filters, "name", s.Name) {
filtered = append(filtered, s)
}
filtered = append(filtered, s)
}
stackList = filtered
}
Expand Down
13 changes: 6 additions & 7 deletions cmd/compose/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/container"
"github.com/docker/docker/api/types/filters"
"github.com/moby/moby/client"
"github.com/spf13/cobra"

"github.com/docker/compose/v2/pkg/api"
Expand Down Expand Up @@ -67,18 +67,17 @@ func runStats(ctx context.Context, dockerCli command.Cli, opts statsOptions, ser
if err != nil {
return err
}
filter := []filters.KeyValuePair{
filters.Arg("label", fmt.Sprintf("%s=%s", api.ProjectLabel, name)),
}
f := client.Filters{}
f.Add("label", fmt.Sprintf("%s=%s", api.ProjectLabel, name))

if len(service) > 0 {
filter = append(filter, filters.Arg("label", fmt.Sprintf("%s=%s", api.ServiceLabel, service[0])))
f.Add("label", fmt.Sprintf("%s=%s", api.ServiceLabel, service[0]))
}
args := filters.NewArgs(filter...)
return container.RunStats(ctx, dockerCli, &container.StatsOptions{
All: opts.all,
NoStream: opts.noStream,
NoTrunc: opts.noTrunc,
Format: opts.format,
Filters: &args,
Filters: f,
})
}
15 changes: 10 additions & 5 deletions cmd/formatter/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ package formatter

import (
"fmt"
"net/netip"
"strconv"
"strings"
"time"

"github.com/docker/cli/cli/command/formatter"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/go-units"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/client/pkg/stringid"
)

const (
Expand Down Expand Up @@ -212,10 +213,14 @@ func (c *ContainerContext) Publishers() api.PortPublishers {
}

func (c *ContainerContext) Ports() string {
var ports []container.Port
var ports []container.PortSummary
for _, publisher := range c.c.Publishers {
ports = append(ports, container.Port{
IP: publisher.URL,
var pIP netip.Addr
if publisher.URL != "" {
pIP, _ = netip.ParseAddr(publisher.URL)
}
ports = append(ports, container.PortSummary{
IP: pIP,
PrivatePort: uint16(publisher.TargetPort),
PublicPort: uint16(publisher.PublishedPort),
Type: publisher.Protocol,
Expand Down
2 changes: 1 addition & 1 deletion cmd/formatter/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"github.com/buger/goterm"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/moby/moby/client/pkg/jsonmessage"
)

// LogConsumer consume logs from services and format them
Expand Down
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ module github.com/docker/compose/v2

go 1.24.9

replace github.com/docker/buildx => github.com/thaJeztah/buildx v0.2.1-0.20251014131213-dc504d137a66 // https://github.com/docker/buildx/pull/3326

// Need a replace, because master pseudo-version is considered "older" than the 28.x branch
replace github.com/docker/cli => github.com/docker/cli v29.0.0-rc.1.0.20251014130057-171a9b70b273+incompatible // master (v29.0.0-dev)

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/DefangLabs/secret-detector v0.0.0-20250403165618-22662109213e
Expand All @@ -15,7 +20,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/distribution/reference v0.6.0
github.com/docker/buildx v0.29.1
github.com/docker/cli v28.5.1+incompatible
github.com/docker/cli v29.0.0-rc.1.0.20251014130057-171a9b70b273+incompatible // master (v29.0.0-dev)
github.com/docker/cli-docs-tool v0.10.0
github.com/docker/docker v28.5.1+incompatible
github.com/docker/go-connections v0.6.0
Expand All @@ -30,6 +35,8 @@ require (
github.com/mitchellh/go-ps v1.0.0
github.com/moby/buildkit v0.25.1
github.com/moby/go-archive v0.1.0
github.com/moby/moby/api v1.52.0-beta.2
github.com/moby/moby/client v0.1.0-beta.2
github.com/moby/patternmatcher v0.6.0
github.com/moby/sys/atomicwriter v0.1.0
github.com/moby/term v0.5.2
Expand Down
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5Qvfr
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/docker/buildx v0.29.1 h1:58hxM5Z4mnNje3G5NKfULT9xCr8ooM8XFtlfUK9bKaA=
github.com/docker/buildx v0.29.1/go.mod h1:J4EFv6oxlPiV1MjO0VyJx2u5tLM7ImDEl9zyB8d4wPI=
github.com/docker/cli v28.5.1+incompatible h1:ESutzBALAD6qyCLqbQSEf1a/U8Ybms5agw59yGVc+yY=
github.com/docker/cli v28.5.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v29.0.0-rc.1.0.20251014130057-171a9b70b273+incompatible h1:G2VeAxjFsbWMhTgf2qE908e32M040txrCkHYzsYCRTo=
github.com/docker/cli v29.0.0-rc.1.0.20251014130057-171a9b70b273+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli-docs-tool v0.10.0 h1:bOD6mKynPQgojQi3s2jgcUWGp/Ebqy1SeCr9VfKQLLU=
github.com/docker/cli-docs-tool v0.10.0/go.mod h1:5EM5zPnT2E7yCLERZmrDA234Vwn09fzRHP4aX1qwp1U=
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
Expand Down Expand Up @@ -324,6 +322,10 @@ github.com/moby/go-archive v0.1.0 h1:Kk/5rdW/g+H8NHdJW2gsXyZ7UnzvJNOy6VKJqueWdcQ
github.com/moby/go-archive v0.1.0/go.mod h1:G9B+YoujNohJmrIYFBpSd54GTUB4lt9S+xVQvsJyFuo=
github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
github.com/moby/locker v1.0.1/go.mod h1:S7SDdo5zpBK84bzzVlKr2V0hz+7x9hWbYC/kq7oQppc=
github.com/moby/moby/api v1.52.0-beta.2 h1:cuilbu4cLBZnlNpJXuv3QTleOxgo3kGqkNGt3ICe1yY=
github.com/moby/moby/api v1.52.0-beta.2/go.mod h1:/ou52HkRydg4+odrUR3vFsGgjIyHvprrpEQEkweL10s=
github.com/moby/moby/client v0.1.0-beta.2 h1:Uy7JhcAOvQAQriowODpHaAJokfw/AhUya0216sk1hAk=
github.com/moby/moby/client v0.1.0-beta.2/go.mod h1:yYEv2G6pYi8u63ga0zlU9KsM7DpoGXubtMaZMJE7/dw=
github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk=
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
github.com/moby/spdystream v0.5.0 h1:7r0J1Si3QO/kjRitvSLVVFUjxMEb/YLj6S9FF62JBCU=
Expand Down Expand Up @@ -470,6 +472,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/thaJeztah/buildx v0.2.1-0.20251014131213-dc504d137a66 h1:GPS+PcI1H6ykqHO2YaaGw2ZiTbSHrEFMGPK+nNdbHsU=
github.com/thaJeztah/buildx v0.2.1-0.20251014131213-dc504d137a66/go.mod h1:SVX7uR2LLY2hMOcI2lOTb/S/9nvbbkdY2yfPIcvXiZk=
github.com/theupdateframework/notary v0.7.0 h1:QyagRZ7wlSpjT5N2qQAh/pN+DVqgekv4DzbAiAiEL3c=
github.com/theupdateframework/notary v0.7.0/go.mod h1:c9DRxcmhHmVLDay4/2fUYdISnHqbFDGRSlXPO0AhYWw=
github.com/tilt-dev/fsnotify v1.4.8-0.20220602155310-fff9c274a375 h1:QB54BJwA6x8QU9nHY3xJSZR2kX9bgpZekRKGkLTmEXA=
Expand Down Expand Up @@ -668,6 +672,8 @@ k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJ
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4=
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro=
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8=
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo=
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA=
Expand Down
2 changes: 1 addition & 1 deletion internal/sync/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"strings"
"sync"

"github.com/docker/docker/api/types/container"
"github.com/moby/go-archive"
"github.com/moby/moby/api/types/container"
"golang.org/x/sync/errgroup"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/tracing/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"time"

"github.com/compose-spec/compose-go/v2/types"
"github.com/docker/docker/api/types/container"
"github.com/moby/moby/api/types/container"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/compose-spec/compose-go/v2/types"
"github.com/containerd/platforms"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/volume"
"github.com/moby/moby/api/types/volume"
)

// Service manages a compose project
Expand Down
Loading
Loading