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?
A docker tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods, and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters.
To rename a docker container, use the rename sub-command as shown, in the following example, we renaming the container discourse_app to a new name disc_app. After renaming a containers, confirm that it is now using the new name. For more information, see the docker-run man page. That's all!
depends_on is a Docker Compose keyword to set the order in which services must start and stop. For example, suppose we want our web application, which we'll build as a web-app image, to start after our Postgres container.
Currently, if you deploy an image with a user, then try to push the image again (to overwrite it) with no delete/overwrite permissions, the docker client returns a successful message. If you try to overwrite the image/tag with a different image, then there will be an error.
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. would give either _ or - depending on which one you used.
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:
Docker Compose discards com.docker.compose.filepaths labels that have None as value. This usually occurs when labels originate from stdin. Added OS X binary as a directory to solve slow start up time issues caused by macOS Catalina binary scan. Passed the HOME environment variable in container mode when running with script/run/run.sh.
Running Dash in Docker This is part one of a short series of posts about Dash. The repository for this blog posts is here. Dash is an application framework to build dashboards (hence the name) or in general data visualization heavy largely customized web apps in Python.
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:
After the last Docker Desktop update, "docker-compose" automatically downgraded to v1.
Now there is a new option to select your "docker-compose" version, which was disabled by default:
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:
-
as expect.-
and _
happened. Anecdotally, I remember having the very same issue a few months back, but after upgrading it went away.docker-compose up
will use the existing container names. This means that it may take you a while to notice the change.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With