I slightly disagree with Alex’s comment. The CAPM does not read as
\begin{align*}
r_{i,t} = r_{f,t}+ \beta_{i} (r_{m,t}-r_{f,t}) + \varepsilon_{i,t}.
\end{align*}
There is an important difference between the single index model (aka market model) (SIM) which
reads as
\begin{align*}
r_{i,t}-r_{f,t}= \alpha_{i} + \beta_{i}(r_{m,t}-r_{f,t}) + \varepsilon_{i,t}
\end{align*}
and the (conditional) capital asset pricing model (CAPM) which reads as
\begin{align*}
\mathbb{E}_t[r_{i,t+1}] - r_{f,t}
&=
\frac{\mathbb{C}\text{ov}_t(r_{i,t+1},r_{m,t+1})}{\mathbb{V}\text{ar}_t[r_{i,t+1}]} \cdot
(\mathbb{E}_t[r_{m,t+1}]-r_{f,t}) \\
&= \beta_{i,t} \cdot (\mathbb{E}_t[r_{m,t+1}]-r_{f,t}).
\end{align*}
(Subscripts indicate that the conditional expectation/variance/covariance is meant). The CAPM is an equilibrium asset pricing model about expected returns which can be, for instance, derived from a stochastic discount factor (SDF) framework assuming the SDF is linear in the market return. In
particular, there is no idiosyncratic risk component $\varepsilon_{i,t}$ and the CAPM makes no statement about realised returns, variances of returns or anything of the sort. It is only concerned with expected returns.
You can immediately see how
the two CAPM equations agree with the equations you quoted: The CAPM implies that the expected excess
return of any asset is proportional to the expected excess return of the market portfolio (value
weighted portfolio of all assets), i.e. $\alpha_{i,t}=0$.
The SIM is purely and merely a statistical (econometric) model which regresses historical returns against the
returns of some factor (this may be a portfolio mimicking the market portfolio but may be any other
factor which is believed to drive the returns). As in a standard OLS regression, the slope coefficient in the SIM model, $\beta_{i}$, is estimated to be
$\frac{\mathbb{C}\text{ov}(r_{i,t}^e,r_{m,t}^e)}{\mathbb{V}\text{ar}[r_{m,t}^e]}$. So, the SIM may be used to test the CAPM empirically (i.e. if the CAPM was true, we would find
$\alpha$ to be not statistically different from zero etc.) but the SIM may not be confused with the CAPM. As a matter of fact, empirical tests raise indeed strong doubts that the CAPM is a good model for average stock returns.