Container names are the right way for containers to find each other. Some things still want an IP: a firewall rule, a DNS server address in a router, a device that only takes numbers. Docker can pin one on a user defined network.
docker network create --subnet 192.0.2.0/24 lan
docker run -d --name dns --network lan --ip 192.0.2.10 example/dns:1.0
The addresses are placeholders; pick a private subnet that is free on your machine. The container gets 192.0.2.10 every time it starts, also after it is recreated. In Compose the network needs an ipam block with the subnet, and the service gets ipv4_address under its network entry.
The subnet is the important part. --ip only works on a user defined network where you set the subnet yourself; on the default bridge Docker refuses it. I would also keep the fixed addresses at one end of the range and let Docker hand out the rest, so a container without a fixed IP never takes the one you reserved. --ip-range on the network can shrink Docker’s automatic pool for that.
A fixed IP is something you have to keep track of. Two containers with the same address cannot both start, and the error only shows up when the second one tries. Unless something outside Docker really needs the number, I would stick to names.
Further reading: docker container run: ip, docker network create