Just to save people from insanity: Docker Desktop packaging appears to be glitchy.
I am running Docker Desktop 4.3.0 (71786) on Windows 11, with the WSL2 backend.

Here are the docker-compose information from my terminal:
% which docker-compose
/usr/bin/docker-compose
% ls -al /usr/bin/docker-compose
lrwxrwxrwx 1 root root 56 Dec 9 19:52 /usr/bin/docker-compose -> /mnt/wsl/docker-desktop/cli-tools/usr/bin/docker-compose
% sha256sum /usr/bin/docker-compose
35dd89af6820dc111991f4c9b8ed7b253fefa33a30392fed506490ddc2553e91 /usr/bin/docker-compose
% docker-compose --version
Docker Compose version v2.2.1
Docker Desktop has been freshly installed. With this version, _
is used as the separator character.
Now, let's switch to the same version of docker-compose, downloaded from GitHub:
% sudo wget -q https://github.com/docker/compose/releases/download/v2.2.1/docker-compose-linux-x86_64 -O /usr/local/bin/docker-compose-v2.2.1-gh
% sudo chmod 755 /usr/local/bin/docker-compose-v2.2.1-gh
% sudo ln -sf /usr/local/bin/docker-compose-v2.2.1-gh /usr/bin/docker-compose
% ls -al /usr/bin/docker-compose
lrwxrwxrwx 1 root root 39 Dec 9 20:18 /usr/bin/docker-compose -> /usr/local/bin/docker-compose-v2.2.1-gh
% sha256sum /usr/bin/docker-compose
68a3bb67bd25abf0f6da2a9d171a873ac182c3cc1c51fb4866e7770675823d2f /usr/bin/docker-compose
% docker-compose --version
Docker Compose version v2.2.1
With the GitHub version, -
is used as the separator character, as expected.
This means that Docker doesn't just repackage the binaries available on GitHub, but make their own builds from a source tree that is different from the one tagged with the same version on GitHub. (Thanks @tentative for pointing out the line of code defining the separator!)
And some final notes:
- docker-compose from other recent versions of Docker Desktop used
-
as expected.
- It is not the first time that switching between
-
and _
happened. Anecdotally, I remember having the very same issue a few months back, but after upgrading it went away.
- If you don't destroy your environment,
docker-compose up
will use the existing container names. This means that it may take you a while to notice the change.
- I have reported this to the GitHub Issue Tracker of Docker for Windows. As of end of 2022, the issue has been fixed.