Search code examples
docker

can default bridge network use host name for DNS resolve?


according to official docs (https://docs.docker.com/compose/networking/):

By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by the service's name.

but isn't that default bridge network is being used in this case? and I heard multiple times that for default brige network, container names cannopt be used as host names, only custom bridge network other thaan default network can use host name for DNS resolve?


Solution

  • Compose always (*) creates a network. It never uses the "default bridge network". If you don't manually declare networks:, Compose creates a network named default for you, but in the language of the documentation, this is a "user-defined bridge network".

    That is, Compose's default behavior is more or less to do

    docker network create default
    docker run --net=default ...
    

    So even though the network is named default, it is not the "default network", and inter-container DNS works normally.


    (*) If you have the now-unsupported version 1 of the Compose tool (in Python), and you are using the obsolete version 1 of the Compose file (without version: or services: tags), this does not have the ability to create networks and only uses the "default bridge network". If you're in this situation, I'd recommend indenting the entire file contents by one step, wrapping it in services:, adding a top-level version: '3.8' declaration, and removing the links: options.