Installation can't reach GitHub or DNS servers

Sounds most likely you have some bad iptables rule, you running stock
iptables?

iptables 1.4.21

Docker doesn’t leave anything behind after it fails (except empty chains
called DOCKER), so I’m not sure what is it that it messes up on the host,
because everything else works on the host, and even other docker containers
unrelated to discourse work from inside (i.e. I can ping external IPs).

If no one else had this problem then it must be something with my host, I
dunno.