Docker compose not setting hostname when network_mode=host

Expected behavior

Have the hostname set in the container
See Allow --hostname with --net=host by jheiss · Pull Request #20177 · moby/moby · GitHub

Actual behavior

Hostname is moby.

Information

  • the output of:
    • Moby Menu > Diagnose & Feedback on OSX
      E35C5561-87C2-40BB-845B-135B23234B85
      Docker for Mac: version: mac-v1.12.0-beta16.2
      OS X: version 10.11.5 (build: 15F34)
      logs: /tmp/20160627-132748.tar.gz
      failure: No error was detected
      [OK] docker-cli
      [OK] app
      [OK] menubar
      [OK] virtualization
      [OK] system
      [OK] osxfs
      [OK] db
      [OK] slirp
      [OK] moby-console
      [OK] logs
      [OK] vmnetd
      [OK] env
      [OK] moby
      [OK] driver.amd64-linux
  • a reproducible case if this is a bug, Dockerfiles FTW
    compose.yml:
    version: ‘2’
    services:
    service1:
    image: nginx
    hostname: myname
    network_mode: host

docker-compose -f compose.yml up -d
docker exec -it _service1_1 hostname
moby

  • host distribution and version: OSX 10.11.x

Steps to reproduce the behavior

  1. copy docker compose file above
  2. start container
  3. check hostname
  4. Same thing happens without compose: docker run --hostname myname --net=“host” nginx
1 Like

FWIW, this does not work the way you expect with Docker Toolbox, either.
Each of the tests above produce the Docker Machine name when I try them.
That, of course, may be a bug in Docker Toolbox as well – I do not know what the expectation there should be.