Stack service containers dynamic hostname

I am migrating away from Docker Cloud to pure Docker Swarm setup. One thing that I am missing is the nice way of how the containers got the hostname set as $SERVICE_NAME-$SLOT_NUMBER.

Is it possible to dynamically set the hostname/container name in a swarm stack service?

While I was posting the question on SO, I figured it out: