The Church’s infallibility is based on the promises of Christ to always be with us and that the Holy Spirit would lead us in the truth. It simply means the whole Church will never defect from the faith. The truth revealed by God for our salvation will always be handed on by the Church so all generations can benefit from it. In other words, not only are the Protestants and other groups wrong who say the Church’s faith was corrupted in the past, what they claim is impossible.
The particular acts of the Church and her pastors are infallible when, if there were an error, the Church’s faith would be definitively corrupted. That’s why definitive dogmatic decisions binding on the whole Church by the entire body of bishops (either in council or spread throughout the world) or their head, the Pope, must be infallible. If they were not the whole Church would follow them into error, which is impossible.
On the other hand, individual Popes and bishops and lay Catholics say and do lots of things that don’t require the absolute assent of the whole Church. They can err as individuals, and so long as the whole Church, doesn’t follow them in their error (which the Holy Spirit prevents).
As for the dogma, doctrine distinction, a doctrine is just a broad term for teaching. A dogma is a truth revealed by God, and, being revealed by God, must be believed with faith. But the pastors of the Church apply these truths and points of the moral law to various situations, they draw logical conclusions from them, etc. These should not be considered revealed dogma.