While focusing on the determination of the number of flat containers in port, on the basis of the analysis of the loading and unloading process, considering different types of containers, handling technology, unit space cost and the income of the yard, a two-stage stochastic programming model with compensation matrix was established. In the model, the yard maximum profits and maximum number of containers per day at the yard were considered as the target and random variable respectively. To solve the required yard capacity and therefore determine the number of flat containers, the maximum profit was considered as the target at the first stage, and the minimum penalty function was considered as the target at the second stage. The results taken from an example showed that the outcome from the two-stage stochastic programming is less than that derived from the standard. Through the analysis of the example, we were able to draw the conclusion that the two-stage stochastic programming can effectively reduce the impact of uncertainties, save costs of land resources, increase the income of the yard, and decrease handling technology costs to obtain the optimal number of flat containers.