This could also be a DNS issue. Altering your nameservers will most likely resolve it, if is indeed related to your DNS.
You can verify the issue with: curl -vvv  https://registry-1.docker.io/v2/ for a more detailed path.
If you are on ubuntu 18.04 or higher /etc/resolve.conf won't do the trick, they moved network management to NetPlan configs.
Add the google nameservers to your configuration (8.8.8.8 and 8.8.4.4)
find your network adapter name with ip a
network:
  version: 2
  renderer: NetworkManager
  ethernets:
      [network adapter name]:
              addresses: ...
              gateway4: ...
              nameservers:
                      addresses:
                              - 8.8.8.8
                              - 8.8.4.4
                      search: []
And run sudo netplan apply