Docker-compose: setting hostname equal to its hostname of where the container is running

If you are running at least Docker 17.10 then you can use something like this:

services:
  daggr:
    hostname: '{{.Node.Hostname}}'

See this for more information.


The selected answer above did not work for me (presumably since I am not running docker/docker-compose in swarm mode).

I was able to set the container hostname for my reverse proxy to match the docker host FQDN by doing the following:

version: '3'

reverse-proxy:
  hostname: $HOSTNAME

This allowed me to easily configure Nginx to pick the correct server cert / key pair prior to startup.