Docker Community Forums

Share and learn in the Docker community.

Possible bug with full hostnames in docker-compose file version 2 vs 2.1?

We have run into a bug with how the hostname is set when using different versions of docker-compose.yml. See this example:

$ cat docker-compose.yml
version: '2'
services:
  bob.test.com:
    hostname: bob.test.com
    image: alpine:latest
    command: hostname
$ docker-compose rm -f && docker-compose up
Going to remove ignition_bob.test.com_1
Removing ignition_bob.test.com_1 ... done
Creating ignition_bob.test.com_1 ... done
Attaching to ignition_bob.test.com_1
bob.test.com_1  | bob
ignition_bob.test.com_1 exited with code 0

$ vi docker-compose.yml
$ cat docker-compose.yml
version: '2.1'
services:
  bob.test.com:
    hostname: bob.test.com
    image: alpine:latest
    command: hostname
$ docker-compose rm -f && docker-compose up
Going to remove ignition_bob.test.com_1
Removing ignition_bob.test.com_1 ... done
Creating ignition_bob.test.com_1 ... done
Attaching to ignition_bob.test.com_1
bob.test.com_1  | bob.test.com
ignition_bob.test.com_1 exited with code 0

As you can see above, when using version 2, the hostname returns bob. With version 2.1, hostname returns bob.test.com. Is the behavior of version 2 intentional? I see this is marked as fixed in https://github.com/docker/compose/issues/4128 , but the release notes don’t mention a specific compose file version.

Thanks!

$ docker-compose --version
docker-compose version 1.24.1, build 4667896b
$ docker --version
Docker version 19.03.2, build 6a30dfc