You can do this without using the fact that $f(X)$ is compact (though it does need the result that compactness implies sequential compactness in metric spaces):
If $f$ is not bounded, then there is a sequence $(x_n)_n$ in $X$ with $\tag{1}|f(x_n)|>n,\quad\text{ for each }n=1,2,\ldots.$
Since $X$ is compact, there is a subsequence $(x_{n_k})_k$ that converges to $x\in X$. Now, by $(1)$, it follows that $f(x_{n_k})$ does not converge to $f(x)$; which implies that $f$ is not continuous on $X$.
Or, you could argue as follows:
Consider the open balls $O_n=\{ y\in \Bbb R: |y| in $\Bbb R$. Then, since $f$ is continuous, $\{ f^{-1}(O_n): n=1,2,\ldots\}$ is an open cover of $X$. Since $X$ is compact, and since $f^{-1}(O_m)\subset f^{-1}(O_n)$ whenever $n>m$, there is an $N$ so that $f^{-1}(O_N)$ covers $X$. This implies that $f$ is bounded.
I prefer the latter argument, as a modification could be made to prove that the continuous image of a compact set is compact.