Despite that deep learning models have achieved remarkable performance in medical image segmentation, their performance is often limited on testing images from new centers with a domain shift. To achieve Domain Generalization (DG) for medical image segmentation, we propose a Domain Composition and Attention-based Network (DCA-Net) combined with structure- and style-based data augmentation that generates unlabeled synthetic images for training. First, DCA-Net represents features in one certain domain by a linear combination of a set of basis representations that are learned by parallel domain preceptors with a divergence constraint. The linear combination is used to calibrate the feature maps of an input image, which enables the model to generalize to unseen domains. Second, considering the number of domains and images for training is limited, we employ generative models to synthesize images with a higher structure diversity, and to leverage the unlabeled synthetic images, we introduce a consistency constraint for their predictions under style augmentation based on frequency amplitude mixture. Additionally, a Test-Time Frequency Augmentation (TTFA) is proposed to neutralize the domain shift from the target to source domains. Experimental results on two multi-domain datasets for fundus structure and nasopharyngeal carcinoma segmentation showed that: (1) our method significantly outperformed several existing DG methods, and (2) the model’s generalizability was largely improved by domain composition and attention modules; (3) by leveraging the unlabeled synthetic images and the TTFA, the model could better deal with images from unseen domains.