How to prevent docker-compose appending hashes to created container names?
This is the new behavior from docker-compose and mirrors the behavior of swarm mode. It doesn't impact the ability to connect the containers via the network at all since there are DNS aliases for the service name that are always included, in your case app
and db
. There's no need for the full container name to connect to a replica of a service using round-robin DNS.
From the release notes:
Important note
The default naming scheme for containers created by Compose in this version has changed from
<project>_<service>_<index>
to<project>_<service>_<index>_<slug>
, where<slug>
is a randomly-generated hexadecimal string. Please make sure to update scripts relying on the old naming scheme accordingly before upgrading.
It's fixed in version 1.23.2:
Reverted a 1.23.0 change that appended random strings to container names created by docker-compose up, causing addressability issues. Note: Containers created by docker-compose run will continue to use randomly generated names to avoid collisions during parallel runs.