Skip to content
Closed
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
3 changes: 3 additions & 0 deletions cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ func (o *ProjectOptions) ToProject(ctx context.Context, dockerCli command.Cli, b
return nil, metrics, err
}

// Warn about deploy attributes that are ignored in standalone mode
warnIgnoredDeployAttributes(project)

return project, metrics, nil
}

Expand Down
74 changes: 74 additions & 0 deletions cmd/compose/warnings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2020 Docker Compose CLI authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package compose

import (
"sort"
"strings"

"github.com/compose-spec/compose-go/v2/types"
"github.com/sirupsen/logrus"
)

// warnIgnoredDeployAttributes emits a warning for deploy attributes that are
// ignored by Compose when running in standalone (non-Swarm) mode, so users
// don't silently rely on configuration that has no effect.
// See https://github.com/docker/compose/issues/13150
func warnIgnoredDeployAttributes(project *types.Project) {
for _, svc := range project.Services {
ignored := collectIgnoredDeployAttributes(svc.Deploy)
if len(ignored) == 0 {
continue
}
sort.Strings(ignored)
logrus.Warnf(
"Service %q uses deploy attributes that are ignored by Compose in standalone mode: %s",
svc.Name,
strings.Join(ignored, ", "),
)
}
}

// collectIgnoredDeployAttributes returns the deploy sub-attributes that are
// consistently ignored in standalone mode. Attributes that are still honored
// (replicas, device reservations, restart_policy fallback) are intentionally
// excluded to avoid noisy or misleading warnings.
func collectIgnoredDeployAttributes(deploy *types.DeployConfig) []string {
if deploy == nil {
return nil
}
var ignored []string
if len(deploy.Placement.Constraints) > 0 {
ignored = append(ignored, "placement.constraints")
}
if len(deploy.Placement.Preferences) > 0 {
ignored = append(ignored, "placement.preferences")
}
if deploy.UpdateConfig != nil {
ignored = append(ignored, "update_config")
}
if deploy.RollbackConfig != nil {
ignored = append(ignored, "rollback_config")
}
if deploy.EndpointMode != "" {
ignored = append(ignored, "endpoint_mode")
}
if deploy.Mode != "" {
ignored = append(ignored, "mode")
}
return ignored
}
61 changes: 61 additions & 0 deletions cmd/compose/warnings_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2026 Docker Compose CLI authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package compose

import (
"testing"

"github.com/compose-spec/compose-go/v2/types"
"gotest.tools/v3/assert"
)

func TestCollectIgnoredDeployAttributes(t *testing.T) {
updateConfig := &types.UpdateConfig{}
t.Run("nil deploy", func(t *testing.T) {
assert.DeepEqual(t, collectIgnoredDeployAttributes(nil), []string(nil))
})
t.Run("no deploy attributes", func(t *testing.T) {
assert.DeepEqual(t, collectIgnoredDeployAttributes(&types.DeployConfig{}), []string(nil))
})
t.Run("supported attributes only", func(t *testing.T) {
replicas := 2
deploy := &types.DeployConfig{
Replicas: &replicas,
}
assert.DeepEqual(t, collectIgnoredDeployAttributes(deploy), []string(nil))
})
t.Run("ignored attributes", func(t *testing.T) {
deploy := &types.DeployConfig{
Mode: "replicated",
EndpointMode: "vip",
UpdateConfig: updateConfig,
RollbackConfig: updateConfig,
Placement: types.Placement{
Constraints: []string{"node.role==manager"},
Preferences: []types.PlacementPreferences{{Spread: "node.labels.zone"}},
},
}
assert.DeepEqual(t, collectIgnoredDeployAttributes(deploy), []string{
"placement.constraints",
"placement.preferences",
"update_config",
"rollback_config",
"endpoint_mode",
"mode",
})
})
}