There exists a bijection $f: \mathbb R \to [0,1]$. Define $d(x,y)=|f(x)-f(y)|$. This makes $\mathbb R$ compact.
The "ultimate generalisation" of such an idea (it's old) is due to Kopperman all topologies come from generalised metrics (Amer. Math. Monthly (95) 1988, nr 2, 89-97). I saw his talk on this around that time...
He considers a semigroup $A$ (so just an associative binary operation) with identity $0$ and $\infty \neq 0$ an absorbing element and calls it a value semigroup if
- If $a+x=b$ and $b+y=a$, then $a=b$. In that case $a \le b$ iff $\exists x: a+x=b$ defines a partial order on $A$.
- For each $b$ there is a unique $a$ so that $b+b =a$ (and we write $b = \frac12 a$).
- For all $a,b$, $a \land b = \inf\{a,b\}$ exists.
- For all $a,b,c$ we have $(a \land b) + c = (a+c) \land (b+c)$.
A set $P \subseteq A$, where $A$ is a value semigroup, is called a
set of positives if
- $a,b \in P \to a \land b \in P$.
- $r \le a$ and $r \in P$ implies $a \in P$.
- if $r \in P$ then $\frac12 r \in P$ as well.
- if $a \le b+r$ for each $r \in P$, then $a \le b$.
Finally, if $X$ is a set, $A$ is a value semi-group, $P \subseteq A$ a set of positives, and $d: X \times X \to A$ a function that obeys $d(x,x)=0$ for all $x$ and $d(x,z) \le d(x,y) + d(y,z)$ for all $x,y,z \in X$, then $(X,A,P,d)$ is called a "continuity space".
For $x \in X, r \in P$ we define $B[x,r] = \{y \in X: d(x,y) \le r\}$ and then $\mathcal{T} = \{O \subset X\mid \forall x \in O: \exists r \in P: B[x,r]\subseteq O\}$ defines a topology on $X$ and (Kopperman's theorem) every topology on $X$ is of this form.
Best Answer
Here is an alternative approach to finding an explicit metric on the cone $CX$.
Let us first assume that $X$ is a subset of a normed linear space $(E, \lVert - \rVert)$ and the metric $d$ on $X$ is given by $d(x,y) = \lVert x - y \rVert$. Define the geometric cone over $X$ as the subset $C'X \subset E' = E \times \mathbb R$ obtained by taking the union all lines segments $L(x) = \{((1-t)x,t) \mid t \in I \} \subset E'$, $x \in X$, connecting $(x,0)$ with $(0,1)$. In other words $$C'X = \{(1-t)x,t) \mid x \in x, t \in I \} .$$ Then $C'X$ is a subset of the normed linear space $(E', \lVert - \rVert')$ where $\lVert (x,t) \rVert' = \lVert x \rVert + \lvert t \rvert$ and therefore inherits a metric $d'$ given by $d'((x,t),(y,s)) = \lVert ((x,t) - (y,s)) \rVert' = \lVert x - y \rVert + \lvert t - s \rvert$.
Now define $$\varphi : X \times I \to C'X, \varphi(x,t) = ((1-t)x,t).$$ This is a continuous map such that $\varphi(X \times \{ 1\}) = \{ (0,1) \}$, hence it induces a continuous $\phi : CX \to C'X$ which is obviously a bijection. If $X$ is compact, then $\phi$ is a homeomorphism. Hence $CX$ can be endowed with the metric $$D([x,t],[(y,s]) = d'(\phi([x,t]),\phi([y,s])) = d'(\varphi(x,t),\varphi(y,s)) \\ = \lVert (1-t)x -(1-s)y \rVert + \lvert t - s \rvert$$ that induces its usual topology.
Now let $(X,d)$ be a metric space with a bounded metric $d$. If $X$ is compact, then $d$ is automatically bounded. Let $C_b(X)$ be the vector space of all continuous bounded maps $f :X \to \mathbb R$ which is endowed with the $\sup$-norm $\lVert f \rVert = \sup_{x\in X} \lvert f(x) \rvert$. It is well-known that $(X,d)$ embeds isometrically into $(C_b(X),\lVert - \rVert)$ via $x \mapsto e(x) = d(x,-) : X \to \mathbb R$. The proof is straightforward. Identifying $X$ with $e(X) \subset C_b(X)$, our above construction yields a geometric cone $C'X$ with metric $d'$. If $X$ is compact, this yields the following metric on $CX$:
$$D([x,t],[y,s]) = \sup_{z \in X} \lvert (1-t)d(x,z) - (1-s)d(y,z) \rvert + \lvert t -s \rvert .$$
This is admittedly less transparent than Eric Wofsey's solution.
Let us close with a remark concerning the geometric cone. If $X$ is not compact, then $C'X$ is not homeomorphic to $CX$. In fact, $CX$ does not have a countable neighborhoood base at its tip whereas $C'X$ is first countable. See my answer to Equivalent definition $\text{Cone}(K)$ which can be generalized to the present case.
Nevertheless, $C'X$ has some essential features attributed to a cone: It is contractible and the inclusion $X \to C'X, x \mapsto (x,0)$, is a cofibration.