I would like to give here a example showing why compactness is important. Consider the following Theorem:

Theorem: Let $f:\mathbb{R}\to \mathbb{R}$ be a continuous coercive function. Then, there exist $x_0\in \mathbb{R}$ such that $$\tag{1} f(x_0)=\inf_{x\in\mathbb{R}}f(x)$$

Proof: Let $I=\inf_{x\in\mathbb{R}}f(x) $ and choose $x_n\in \mathbb{R}$ with $f(x_n)\to I$. We claim that $x_n$ is bounded. Indeed, if $x_n$ was not bounded, then we could extract a subsequence of $x_n$ not relabeld such that $f(x_n)\to \infty$ (by coercivity) which is an absurd. Now, $x_n$ being bounded implies without loss of generality that (compactness) $x_n\to x$. Because $f$ is continuous, we conclude that $f(x_n)\to f(x)=I$.

The main argument of the proof was the fact that the closure of any bounded set in $\mathbb{R}$ is compact. Now consider the problem ($\Omega\subset\mathbb{R}^N$ bounded domain)

$$
\tag{P} \left\{ \begin{array}{ccc}
-\Delta u =f&\mbox{ in $\Omega$} \\
u\in H_0^1(\Omega) &\mbox{ }
\end{array} \right.
$$

We say that $u\in H_0^1(\Omega)$ is a solution of (P) if $$\int_\Omega\nabla u\nabla v=\int_\Omega fv,\ \forall\ v\in H_0^1(\Omega)\tag{3}$$

Let $F:H_0^1(\Omega)\to \mathbb{R}$ be defined by $$F(u)=\frac{1}{2}\int_\Omega |\nabla u|^2-\int_\Omega fu$$

$(3)$ is equivalently to $\langle F'(u),v\rangle =0$ for all $v\in H_0^1(\Omega)$ and this equality is equivalently to find a local minimum of $F$ in $H_0^1(\Omega)$. One can check that $F$ is continuous and coercive, so we could try to use the same argument as above to find a minimum to $F$, but the problem here is lack of compactness, i.e. if $K\subset H_0^1(\Omega)$ is bounded we can't conclude that the closure of $K$ is compact.

Therefore to see how important compactness is, the above problem can be solved by considering a new topology in $H_0^1(\Omega)$, to wit, the weak topology. In this topology we have less open sets which implies more compact sets and in particular, bounded sets are pre-compact sets. It can be show that $F$ is weakly sequentially lower semi continuous, i.e. $F$ is lower sequentially continuous in the weak topoogy, which together with coercivity implis the existence of a minimum.

To conclude,take a look on these examples (they show how worse can be lack of compactnes): here and here.