5. Place eight balls, each with a radius of 1, in two layers inside a cylinder such that each ball is tangent to its four adjacent balls, and to one base and the side of the cylinder. Then the height of the cylinder is $\qquad$ .
5. $\sqrt[4]{8}+2$ As shown in the figure, the centers of the four balls in the upper and lower layers, $A^{\prime}, B^{\prime}, C^{\prime}, D^{\prime}$ and $A$, $B, C, D$, are the vertices of two squares with side lengths of 2, and the circumcircles $\odot O^{\prime}$ and $\odot O$ of these squares form the top and bottom bases of a cylinder.
In $\triangle A^{\prime} A B$, $A^{\prime} A=A^{\prime} B=A B=2$.
Let the midpoint of $A B$ be $N$, and the projection of $A^{\prime}$ on the lower base be $M$,
then $A^{\prime} N=\sqrt{3}$, and points $O, N, M$ are collinear.
Also, $O M=O^{\prime} A^{\prime}=\sqrt{2}, O N=1$.
Therefore, $M N=\sqrt{2}-1, A^{\prime} M=\sqrt{\left(A^{\prime} N\right)^{2}-(M N)^{2}}=\sqrt{2 \sqrt{2}}=\sqrt[4]{8}$.
Thus, the height of the cylinder is $\sqrt[4]{8}+2$.