Docker network IP allocation issue

Hello,

I am running 2 docker container one is apache (webserver) and other is MySQl (dataserver).
I created a network, network details are given below.

            "Name": "dataserver",
            "EndpointID": "d3f070376cb77a2b0d61b21b2b8ba6f72e60f127d3e09a14f07acab199316110",
            "MacAddress": "02:42:ac:12:00:03",
            "IPv4Address": "172.18.0.3/16",
            "IPv6Address": ""
        },
        "dd66c6cfb221d715141be2df2bb7dd0a94224d741b811670867a2112fd576c58": {
            "Name": "webserver",
            "EndpointID": "de664313d5e6b4bdfc2692f8c700da09f8ba34582d4f51004cf48d1568de2032",
            "MacAddress": "02:42:ac:12:00:02",
            "IPv4Address": "172.18.0.2/16",
            "IPv6Address": ""

Here, I am using host 172.18.0.3 to connect to DB from the webserver. But when I restart the container the IP allocate to them is interchanged, due to this I cannot connect to the DB server from webserver.
Do I need to change each time my web server configuration to connect to DB or any other method is available?

You should to configure your Web server container to use the container name of the database container as a DNS name (that is, set something like MYSQL_HOST=dataserver). Docker provides an internal DNS service that will resolve it to the correct place. You should never be looking at these IP addresses (as you note they change routinely).