It looks like the project name can be set using the name top level element in the docker-compose file as described here: https://docs.docker.com/compose/compose-file/#name-top-level-element
Top-level name property is defined by the specification as project name to be used if user doesn’t set one explicitly. Compose implementations MUST offer a way for user to override this name, and SHOULD define a mechanism to compute a default project name, to be used if the top-level name element is not set.
This doesn't seem to be well documented anywhere else, and I didn't see a reference to it in the spec changelog, so I'm not sure if this has always been part of the spec, or if compose just didn't support it until recently.
Example
My current directory (pwd):
/Users/brahmlower/development/compose-test
My compose file (cat docker-compose.yml):
version: "3.8"
name: my-project
services:
hello-world:
image: "hello-world:latest"
Without the name property, we would expect to see the stack started with the prefix compose-test since that's the name of the directory. However when I bring the stack up, we see compose names the stack my-project as expected.
The stack output (docker compose up -d):
[+] Running 2/2
⠿ Network my-project_default Created
⠿ Container my-project-hello-world-1 Started
Versions
In case it's helpful, my docker versions are:
compose (docker compose version):
Docker Compose version v2.10.2
docker (docker version):
Client:
Cloud integration: v1.0.29
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:04:45 2022
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Desktop 4.12.0 (85629)
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:01:01 2022
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
name: my-projecttop level element in the docker-compose file. See answer below