From c0345e4f451f3ff06fec4bece11d6672a384d261 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 5 Dec 2025 13:13:52 +0100 Subject: [PATCH] restore support for COMPOSE_COMPATIBILITY Signed-off-by: Nicolas De Loof --- cmd/compose/compose.go | 2 +- pkg/api/env.go | 20 ++++++++++++++++++++ pkg/compose/loader.go | 3 ++- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 pkg/api/env.go diff --git a/cmd/compose/compose.go b/cmd/compose/compose.go index ad58555a1..2aad5472b 100644 --- a/cmd/compose/compose.go +++ b/cmd/compose/compose.go @@ -59,7 +59,7 @@ const ( // ComposeProjectName define the project name to be used, instead of guessing from parent directory ComposeProjectName = "COMPOSE_PROJECT_NAME" // ComposeCompatibility try to mimic compose v1 as much as possible - ComposeCompatibility = "COMPOSE_COMPATIBILITY" + ComposeCompatibility = api.ComposeCompatibility // ComposeRemoveOrphans remove "orphaned" containers, i.e. containers tagged for current project but not declared as service ComposeRemoveOrphans = "COMPOSE_REMOVE_ORPHANS" // ComposeIgnoreOrphans ignore "orphaned" containers diff --git a/pkg/api/env.go b/pkg/api/env.go new file mode 100644 index 000000000..463193424 --- /dev/null +++ b/pkg/api/env.go @@ -0,0 +1,20 @@ +/* + 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 api + +// ComposeCompatibility try to mimic compose v1 as much as possible +const ComposeCompatibility = "COMPOSE_COMPATIBILITY" diff --git a/pkg/compose/loader.go b/pkg/compose/loader.go index a0891c703..9a0699da7 100644 --- a/pkg/compose/loader.go +++ b/pkg/compose/loader.go @@ -28,6 +28,7 @@ import ( "github.com/docker/compose/v5/pkg/api" "github.com/docker/compose/v5/pkg/remote" + "github.com/docker/compose/v5/pkg/utils" ) // LoadProject implements api.Compose.LoadProject @@ -48,7 +49,7 @@ func (s *composeService) LoadProject(ctx context.Context, options api.ProjectLoa } } - if options.Compatibility { + if options.Compatibility || utils.StringToBool(projectOptions.Environment[api.ComposeCompatibility]) { api.Separator = "_" }