We use Langevin dynamics to study the deformations of linear and ring polymers in different confinements by applying compression and stretching forces on their two sides. Our results show that the compression deformations are the results of an interplay among of polymer rigidity, degree of confinement, and force applied. When the applied force is beyond the threshold required for the buckling transition, the semiflexible chain under the strong confinement firstly buckles; then comes helical deformation. However, under the same force loading, the semiflexible chain under the weaker confinement exhibits buckling instability and shrinks from the folded ends/sides until it becomes three-folded structures. This happens because the strong confinement not only strongly reduces the buckling wavelength, but also increases the critical buckling force threshold. For the weakly confined polymers, in compression process, the flexible linear polymer collapses into condensed states under a small external force, whereas the ring polymer only shows slight shrinkage, due to the excluded volume interactions of two strands in the crowded states. These results are essential for understanding the deformations of the ring biomacromolecules and polymer chains in mechanical compression or driven transport.