Abstract Rolling bearings are essential components in various industrial machines, and their failures can lead to significant downtime and maintenance costs. Traditional data-driven fault diagnosis methods often require extensive fault datasets for training, which may not always be available in critical industrial scenarios, limiting their practicality. Digital twins, virtual representations of physical entities reflecting their operational conditions, offer a promising solution for the fault diagnosis of rolling bearings with limited fault data. In this paper, we propose a novel digital twin-driven framework to address the challenge of limited training data in rolling bearing fault diagnosis. Firstly, a virtual bearing simulation model is used to generate the simulated data. Subsequently, a transformer-based network is introduced to learn the discrepancy features from the raw data. Then, a Maximum Mean Discrepancy loss and a supervised contrastive learning loss for raw and augmentation data are established to achieve global domain alignment and instance-based domain alignment. Finally, an unsupervised contrastive learning loss for the augmentation data of the target domain is established to further improve the diagnostic performance. In five cross-domain fault diagnosis tasks representing real industrial scenarios set in this study, the proposed method achieved an average diagnostic accuracy of 84.40%, exceeding two existing advanced domain adaptation methods by more than 10%. The experimental results demonstrate that the proposed method achieves high diagnostic performance in real industrial scenarios where labeled data is lacking. This shows its significant benefits for monitoring the condition of critical bearings.