John Donne's poetry and sermons, especially after he became a priest in 1615, are deeply religious. Understanding the contents and evolution of his religious beliefs helps us understand his poetry better.
The sixteenth and seventeenth centuries were ones of great religious turmoil in Europe and Britain, when thousands of people died every year for their religious faiths. The theological differences between Catholicism and Protestantism were matters of life and death, both considered from a theological perspective (of eternal salvation) and a worldly one (you could be killed for your religion). England had a long a bloody history of religious conflict, beginning with King Henry VIII's creation of the Protestant Church of England by the Act of Supremacy in 1534, which actually outlawed Roman Catholicism. The beliefs of the Henrician church were in part encapsulated in the 42 Articles of 1553. Those people who remained Roman Catholics, know as "recusant Catholics," were persecuted. When Henry's daughter Mary I, known as "Bloody Mary" to Protestants, acceded to the throne, she restored Roman Catholicism, and burned 283 leading Protestants at the stake. Her successor, Elizabeth I, restored the Protestant Church of England as the state religion in 1559, and though Roman Catholics suffered many civil disabilities, Elizabeth was, by the standards of her period, more pragmatic than fanatic concerning religion. The Thirty-Nine Articles, based on the earlier Henrician 42 articles, represent a doctrine that is often described as a "via media" (Latin for "middle path") between extreme Protestantism and Catholicism; they can be described as moderately Calvinist in theology but moderately Catholic in liturgy (Anglican church services are basically English translations of the Latin Roman Catholic ones in use at the period).
What makes all of this important for Donne is that he came from a recusant Catholic family. One of his uncles had been sentenced to death for being a Jesuit (an order of Catholic monks) and his brother died in the prison to which he was sentenced for helping a Roman Catholic. While Donne was in his twenties and thirties, he was a socialite and courtier, and wrote witty, often sexually themed poems, albeit with some religious themes. At some time within this period he joined the Church of England (also called the "Anglican" Church), but it wasn't until the 1600s, when he married and settled down, that his work began to take a more devout turn.
One of the major paths to career advancement that was open to educated men of his period was the priesthood, but despite the urgings of his friends (and probably due to his family history) he was quite reluctant to take this path. What his poems record is that the decision was not a cynical one based on whether it would be a good job, but rather an agonizing struggle with the question of whether he had a vocation and whether he was worthy of the position. A key poem reflecting on this decision was "Good Friday, 1613. Riding Westward," in which Donne compares the business of daily life (the west) to the place of Christ's sacrifice (the East).
As Donne meditates upon the path to salvation, he enters into an area where Protestants and Catholics disagree, namely the degree to which church rituals, good works, faith, or grace contribute to salvation. Donne's position in his poems follows in some detail the theology laid out in the Thirty-Nine Articles rather than that of the Catholicism of his childhood. Rather than doing acts of penance or ritual observances such as confession, pilgrimage, using a rosary, or spending many hours attending church services, his poems emphasize private prayer, reflection, and struggle.
Even more specifically reflecting the Calvinism of the Thirty-Nine Articles is the emphasis on his inability to save himself by means of will or good works, following the theological formulation of Article XI:
XI Of the Justification of Man. We are accounted righteous before God, only for the merit of our Lord and Saviour Jesus Christ by Faith, and not for our own works or deservings.
Instead, God must, in a sense, force salvation upon humans. This doctrine, called "irresistible grace," is portrayed in Donne's poems as an almost violent and painful thrusting of salvation upon the sinner by God. In "Good Friday, 1613. Riding Westward," Donne uses the metaphor of whipping, of God beating grace into the sinner's back until the sinner is worthy to turn east and face God:
I turne my backe to thee, but to receiveCorrections, till thy mercies bid thee leave.O thinke mee worth thine anger, punish mee,Burne off my rusts, and my deformity,Restore thine Image, so much, by thy grace,That thou may'st know mee, and I'll turne my face.
Batter my heart, three-person'd God, for youAs yet but knock, breathe, shine, and seek to mend;That I may rise and stand, o'erthrow me, and bendYour force to break, blow, burn, and make me new.