I always used docker-compose on Ubuntu, in this environment containers are named with underscore:
But now, I switched to Windows 10 (using Docker Desktop) and naming convention has changed:
I don't know if this is OS dependent but it's a problem. My scripts are failing because they rely on containers named with underscores.
Is there a way to customize this and use underscore instead of dashes?
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:
--compatibility
flag with docker-compose
commandsCOMPOSE_COMPATIBILITY=true
environment variableOther doc links: