This naming convention difference appears to be a difference between Docker Compose versions v1 (Python) and v2 (Go). The latest docker/compose repo that is packaged with Docker Desktop is the golang version in the docker/compose v2 branch. Looking at the source code here in this branch:
// Separator is used for naming components
var Separator = "-"
The python branch source code is using the _ naming convention for components, here for example:
def rename_to_tmp_name(self):
"""Rename the container to a hopefully unique temporary container name
by prepending the short id.
"""
if not self.name.startswith(self.short_id):
self.client.rename(
self.id, '{}_{}'.format(self.short_id, self.name)
)
As to solving this, you may want to uninstall the compose included with Docker Desktop and revert to a 1.28.x version. The compose readme says you can use pip install docker-compose to install. The compose docs have a section about upgrading this and commands to migrate to v2: https://docs.docker.com/compose/install/#upgrading but your question suggests you want to stay with the _ v1 naming convention.
As mentioned in comments, the following options retain the compose compatibility:
- use
--compatibilityflag withdocker-composecommands - set
COMPOSE_COMPATIBILITY=trueenvironment variable
Other doc links:
- Backward compatibility is discussed here: https://github.com/docker/compose#about-update-and-backward-compatibility
- Docs/Readmes suggest installing compose-switch for translating docker-compose commands
- If you instead want to upgrade to v2 on Ubuntu and modify scripts: https://docs.docker.com/compose/cli-command/#install-on-linux