Imagine a container container containing 1 mole of a gas at STP ..... with volume less than 22.4 lts.
The gas tries to occupy 22.4 lts. but can't .... so its random molecules exerts a continuous pressure on the walls of the container .... but the container walls exert a force back [ Newton's law ]...
For a container with more than 22.4 lts. capacity ... the gas is unevenly distributed within the container [ as we know that molecules of a gas have random motion ] So we tell that a gas takes the shape of the container ...
*** Note: In the second case ... the gas is subjected to no tension ... hence no compression .... ***