The emergence of multi-access edge computing (MEC) aims at extending cloud computing capabilities to the edge of the radio access network. As the large-scale IoT services are rapidly growing, a single edge infrastructure provider (EIP) may not be sufficient to handle the data traffic generated by these services. The coalition method has been used in MEC for resource optimization, latency, energy consumption reduction, computation offloading, etc. However, the majority of research does not consider the price of computing resources corresponded to a container. Moreover, each SP does not choose EIP with the highest cost-performance to sign a medium/long-term computing resource purchase or lease contract. In this work, we consider a scenario with a collection of SPs with different budgets and several EIPs distributed in geographical locations. During the first phase, we get the market equilibrium price and select the optimal EIPs to make a deal by solving the Eisenberg-Gale convex program. In the second stage, using a mathematical model, we maximize EIP's profits and form stable coalitions between EIPs by a distributed coalition formation algorithm. Numerical results demonstrate that the effectiveness of our method is significantly better than the existing model.