Docker Community Forums

Share and learn in the Docker community.

Docker compose not setting hostname when network_mode=host

(Roelandvanbatenburg) #1

Expected behavior

Have the hostname set in the container

Actual behavior

Hostname is moby.


  • the output of:
    • Moby Menu > Diagnose & Feedback on OSX
      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
    version: '2’
    image: nginx
    hostname: myname
    network_mode: host

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

  • 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

(Kvc4code) #2

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.