compose/pkg/e2e/api_socket_test.go
Nicolas De Loof 821153b2e4 fix(start): give a started use_api_socket service its config file
A container created beforehand and only started by `compose start`
(`create` then `start`, `up --no-start` then `start`, or a dependency named
to `start`) came up with DOCKER_CONFIG pointing at /run/secrets/docker and no
file there: use_api_socket is applied by rewriting the project, and the
config file it adds is injected when a container starts, from the project the
start works on. Create and run applied the rewriting, start did not.

start() now applies it too, on the copy it already makes of the project, so
the caller's is left alone, and a project already rewritten (a dependency
started by run) is not rewritten twice. The rewriting tolerates a project
without environment or configs maps, as the one `compose start` loads.

up -d, a foreground up, scale and run already provided the file.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-26 17:16:24 +01:00

41 lines
1.6 KiB
Go

//go:build e2e
/*
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 e2e
import (
"testing"
"time"
)
// Regression test for https://github.com/docker/compose/issues/14386: a
// container created beforehand and only started by `compose start` got
// DOCKER_CONFIG pointing at /run/secrets/docker, without the config file the
// use_api_socket option is meant to provide there. The file is injected when
// the container starts, from the project given to the start, which did not
// carry the option.
func TestStartCreatedUseAPISocketService(t *testing.T) {
NewScenario(t, "start must provide the use_api_socket config file to a container created beforehand").
Step("create makes the container without starting it",
ComposeCmd("create"),
ServiceState("app", "created")).
Step("start runs it with the config file in place",
ComposeCmd("start"),
Eventually(ServiceState("app", "running"), 10*time.Second),
ExecOutputContains("app", "[ -f /run/secrets/docker/config.json ] && echo apisocket-config-present", "apisocket-config-present"))
}