8

I have a server with several lxc containers. In some of the containers there is a docker installed. Usually a docker compose action in these LXC containers results in container names with the format appname_service_1, e.g. wordpress_app_1 and wordpress_db_1, when app and db are two services which are called in the wordpress compose file - you know it.

But today i created another LXC container and installed docker in it. The setup is identical to the other containers, thanks to ansible. However, the docker container names are different, e.g. wordpress_db_1_c9de200f9abd. The hash at the end differs whenever i delete the container and re-create it.

Since this makes containers not so disposable as they should be, because it destroys any routes between the containers, i'd like to know why this hashes are appended at all. All LXC containers have the same docker and the same docker-compose version installed. I'd like to prevent these hashes in my docker container names at all.

Why are they now occuring and didn't occur before?

j4r3k
  • 3
  • 1
simonszu
  • 343
  • 5
  • 14

2 Answers2

7

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.

BMitch
  • 5,189
  • 1
  • 21
  • 30
  • 2
    It's a change of the version 1.23.0 from 31th October. Here the discussion https://github.com/docker/compose/issues/6316 – hernanvicente Nov 27 '18 at 15:31
6

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.

barney765
  • 171
  • 3