The container relocation problem (CRP) is an important factor affecting the operation efficiency of container terminal yards, and it has attracted much attention for decades. The CRP during the pickup operations of import containers is still an intractable problem for two reasons: the first is that the solution efficiency of the algorithms developed in the existing literature cannot meet the real-time operation requirements; the second is that the pre-optimized operation plan cannot cope with the changes in the real-time operation scenarios caused by the uncertainty of the arrival time of external trucks. This paper proposes an optimization method for the real-time operation scenario which aims to solve the most reasonable operation plan quickly according to the arrivals of external trucks, in which a dynamic upper bound of the optimal solution is derived based on the dynamic programming model of the import containers’ CRP, and an approximate optimal solution can be obtained by minimizing this dynamic upper bound. A heuristic algorithm based on three relocation rules is developed to implement this method, considering the adjustment of the pickup sequence of the target containers. Numerical experiments show that (1) when the number of a batch of target containers is less than 10 (excluding target containers that can be directly picked up), the method proposed in this paper can solve the problem quickly to meet the demand of optimizing real-time pickup operations; (2) compared with other outstanding algorithms, the quality of the solutions obtained by this method is also improved; and (3) this method can be applied to the most container terminals for optimizing real-time pickup operations.