Problem:

Docker runs its own container DNS that means you can easily link containers together just by specifying their names, instead of having to work out their dynamically assigned IP's somehow. Unfortunately NGINX doesn't read the /etc/hosts file that docker edits, and so can't resolve hostnames of other containers.

Solution:

An earlier hacky solution was to bundle dnsmasq in with nginx and have it use 127.0.0.1 as a resolver, violating the one process per container best practice.

As of Docker 1.10 you can use the new embedded DNS feature by setting 127.0.0.11 as the resolver in nginx.conf, just be aware that there are issues with IPv6.