dockerdocker-compose

How do I set hostname in docker-compose?


In my docker-compose.yml file, I have the following. However the container does not pick up the hostname value. Any ideas?

dns:
  image: phensley/docker-dns
  hostname: affy
  domainname: affy.com
  volumes:
    - /var/run/docker.sock:/docker.sock

When I check the hostname in the container it does not pick up affy.


Solution

  • As of Docker Compose file version 3.0 and later, you can just use the hostname key:

    version: "3.0"
    services:
      yourservicename:
        hostname: your-name