Using Ampere's Law for a Solenoid 
(source: gsu.edu)
To calculate the magnetic field, a rectangle amperian loop was drawn, and since the sides of the rectangle are perpendicular to the magnetic field, and the top is too far away to have any field lines cross it, only BL makes a contribution.

(source: gsu.edu)
I don't understand why this magnetic field is only contained within the solenoid. Shouldn't the magnetic field at any point on the amperian loop equal μnI, according to Ampere's law?
 A: Solenoids of finite length do have a non-zero magnetic field outside. As the length increases, this magnetic field is significantly smaller than the magnetic field inside the solenoid. An ideal solenoid has infinite length and this magnetic field is zero. One is usually dealing with this idealisation. This is similar to assuming that there is no electric field outside a parallel plate capacitor. It is a fun (not necessarily easy) problem to estimate the ratio of the interior and exterior magnetic fields for a finite solenoid.
A: You're on the right track. Now consider a second Amperian loop, shaped like the first, but with the bottom outside the solenoid. The current passing through this loop is zero, and you've already decided that the far end of the loop doesn't contribute, so you must conclude that $B_{out} = 0$. 
You could do the same thing with a rectangular Amperian loop with the top and bottom at $s_{t}$ and $s_{b}$, respectively, where $s$ is the distance from the axis. If $s_{t}$ and $s_{b}$ are both outside the cylinder (and assuming $B$ is a function of $s$, which you may deduce from symmetries) you would find $B_{out}(s_{b})L - B_{out}(s_{t})L = 0$. Thus, $B_{out}$ must be constant, and the requirement that it goes to zero far away means that the constant must be zero.
