Bubble detection has important applications in industries such as tightness testing, fluid measurement, healthcare, and chemical engineering. Due to the fact that bubbles belong to small targets with characteristics such as reflection and shadows, they have fewer available features and are highly susceptible to environmental interference, which makes it difficult for detection models to accurately locate and recognize the bubbles. Aiming at these problems, an improved YOLOv8n for bubble detection is proposed. Firstly, the deformable convolution network (DCN) is used in the Backbone module to take place of the original C2f module, which enables the model to have stronger feature extraction and adaptive generalization capabilities for small targets with different deformations. Then the global attention mechanism (GAM) is introduced into Neck network to locally enhance the channels or regions of interest, which is beneficial for capturing the important features of targets, especially small targets like bubbles. Finally, the loss function is improved so that boundary box regression and target detection become more accurate. Experiments are conducted on the bubble dataset, and the results indicate the mean average precision (mAP) of the improved algorithm reaches 97.4%, increasing by 2.2% compared to the original YOLOv8n.This shows the proposed method has better comprehensive performance on bubble detection.