Effective berth allocation in container terminals is crucial for optimizing port operations, given the limited space and the increasing volume of container traffic. This study addresses the discrete dynamic berth allocation problem (DDBAP) under uncertain ship arrival times and varying load capacities. A novel deep Q-network (DQN)-based model is proposed, leveraging a custom state space, rule-based actions, and an optimized reward function to dynamically allocate berths and schedule vessel arrivals. Comparative experiments were conducted with traditional algorithms, including ant colony optimization (ACO), parallel ant colony optimization (PACO), and ant colony optimization combined with genetic algorithm (ACOGA). The results show that DQN outperforms these methods significantly, achieving superior efficiency and effectiveness, particularly under high variability in ship arrivals and load conditions. Specifically, the DQN model reduced the total waiting time of vessels by 58.3% compared to ACO (262.85 h), by 57.9% compared to PACO (259.5 h), and by 57.4% compared to ACOGA (257.4 h), with a total waiting time of 109.45 h. Despite its impressive performance, DQN requires substantial computational power during the training phase and is sensitive to data quality. These findings underscore the potential of reinforcement learning to optimize berth allocation under dynamic conditions. Future work will explore multi-agent reinforcement learning (MARL) and real-time adaptive mechanisms to further enhance the robustness and scalability of the model.