If you're running docker on an EC2 instance, and you face this issue, one of the things you need to check is your outbound rules on your security group. You'll need add a rule that allows all traffic, and destination should be "Anywhere-IPv4". Save the rule and run your command again.