Docker compose HOSTNAME env works differently than in docker run

The hostname directive does not work properly in docker compose as the environment variable HOSTNAME does not contain the full domain name.

$ docker run --hostname host.dom.example.com busybox hostname
host.dom.example.com

And

$ docker run --hostname host.dom.example.com busybox printenv HOSTNAME
host.dom.example.com

But in docker compose:

$ cat > test.yml <<'EOF'
version: '2'
services:
  host.dom.example.com:
    image: busybox
    hostname: host.dom.example.com
    command: printenv HOSTNAME
EOF
$ docker-compose -f test.yml up
host.dom.example.com_1  | host

Not:

host.dom.example.com_1  | host.dom.example.com

Yet:

cat > test2.yml <<'EOF'
version: '2'
services:
  host.dom.example.com:
    image: busybox
    hostname: host.dom.example.com
    command: hostname
EOF
$ docker-compose -f test2.yml up
host.dom.example.com_1  | host.dom.example.com

I’ve also posted as bug to github here