How to get Docker containers to communicate by name instead of ip-address`?

Docker adding all new containers default to a bridge network but on the default bridge network you only can communicate between containers with ip-address, to communicate with containers name instead you need to define your own bridge network:

docker network create --driver bridge network01 --subnet=

Then when you run the container add –network network01 to let the container connect to the new network and you can then communicate between containers by using the name you set on the container instead of communicate by ip-address that changes after a reboot and other things.