# Docker compose not setting hostname when network\_mode=host

**URL:** <https://forums.docker.com/t/docker-compose-not-setting-hostname-when-network-mode-host/16728>\
**Category:** Docker Desktop\
**Created:** [June 27, 2016, 11:39am UTC](https://forums.docker.com/t/docker-compose-not-setting-hostname-when-network-mode-host/16728 "2016-06-27T11:39:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roelandvanbatenburg](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@roelandvanbatenburg](https://forums.docker.com/u/roelandvanbatenburg)\
**Post date:** [June 27, 2016, 11:39am UTC](https://forums.docker.com/t/docker-compose-not-setting-hostname-when-network-mode-host/16728/1 "2016-06-27T11:39:08Z")

</div>

### Expected behavior

Have the hostname set in the container  
See [Allow --hostname with --net=host by jheiss · Pull Request #20177 · moby/moby · GitHub](https://github.com/docker/docker/pull/20177)

### 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

---

<div class="post-metadata">

**Author:** ![kvc4code](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/kvc4code/32/7515_2.png) [@kvc4code](https://forums.docker.com/u/kvc4code)\
**Post date:** [June 28, 2016, 3:18am UTC](https://forums.docker.com/t/docker-compose-not-setting-hostname-when-network-mode-host/16728/2 "2016-06-28T03:18:17Z")

</div>

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.
