Viruses exist for one purpose only: to reproduce. To do that, they have to take over the reproductive machinery of suitable host cells.
Upon landing on an appropriate host cell, a virus gets its genetic material inside the cell either by tricking the host cell to pull it inside, like it would a nutrient molecule, or by fusing its viral coat with the host cell wall or membrane and releasing its genes inside. Some viruses inject their genes into the host cell, leaving their empty viral coats sitting outside.
If a virus is a DNA virus, its genetic material then inserts itself into the host cell's DNA. If the virus is an RNA virus, it must first turn its RNA into DNA using the host cell's machinery before inserting into the host DNA. The viral genes are then copied many, many times, using the machinery the host cell would normally use to reproduce its own DNA. The virus uses the host cell's enzymes to build new viral capsids and other viral proteins. The new viral genes and proteins then come together and assemble into whole new viruses. The new viruses are either released from the host cell without destroying the cell or eventually build up to a large enough number that they burst the host cell like an overfilled water balloon.