Docker : Not able to access other website or git inside a docker ? Solved

Consider an example when you are trying to connect git within the docker 

The error message fatal: unable to access ‘’: Could not resolve host: is showing that the DNS resolution for is failing within the Docker executor. Here are a few things that you can check to diagnose and resolve this issue:

  1. DNS Resolver within Docker: Check if DNS resolution is working inside your Docker containers. You can run a new container and try to resolve from within it. Here’s an example using the busybox image:
    docker run -it --rm busybox nslookup
If the DNS resolution fails inside the container, but works on the host machine, you might have an issue with your Docker DNS settings.
  1. Network Rules: Make sure there are no network rules blocking the Docker executor from making a request to This could be a security group rule, network ACL, firewall rule, etc.
  2. Container Networking: Ensure your Docker container has the correct network settings and is not isolated in a way that prevents it from reaching the outside network.
  3. Docker Image: There could be a problem with the Docker image If the image is built in such a way that it alters network settings or doesn’t include necessary tools or libraries for Git operations, it might cause the issue.
  4. Git Settings in Docker: Git may be misconfigured in the Docker image. You can enter the container and try to clone the repository manually to see if you encounter any issues.

Please note that although you are able to ping from the EC2 instance, it doesn’t guarantee that the Docker container running on the same EC2 instance can also reach DNS resolution could be working differently depending on the environment settings.

Once you run

  1. docker run -it --rm busybox nslookup
Still you are getting as  connection timed out; no servers could be reached 

It seems like the DNS resolution is not working inside your Docker containers. This could be due to Docker’s DNS configuration. Docker by default uses Google’s public DNS server ( for DNS resolution, but in certain environments this server might be unreachable.

You can try changing Docker’s DNS settings to use a different DNS server. You can use the DNS server that your host machine uses, which can usually be found in the /etc/resolv.conf file.

Here is how you can do it:

  1. Edit (or create) the Docker daemon configuration file, typically located at

The default path for Docker’s daemon configuration file is /etc/docker/daemon.json. However, this file is not created automatically when Docker is installed, so you might not find it if you’ve never modified Docker’s settings before. If the file doesn’t exist, you can create it.

Here’s how you do it:

  1. Run the following command to create the daemon.json file:
sudo touch /etc/docker/daemon.json
  1. Open the file in a text editor. For example, you can use nano:
sudo nano /etc/docker/daemon.json
  1. Enter the following JSON to set your DNS:
   "default-address-pools": [{

You need to get the above information from your administrator

  1. Save the file and exit the editor.
  2. Restart the Docker service for the changes to take effect:
sudo systemctl restart docker

DNS server address is not the address of your EC2 instance. A DNS (Domain Name System) server is responsible for translating domain names (like into IP addresses that can be understood by computers.

The /etc/docker/daemon.json file is Docker’s configuration file, where you can customize various Docker daemon parameters.

In your provided configuration, you are defining a default address pool for Docker’s networks. Let’s break it down:

  1. “default-address-pools”: This is an array of IP address pools from which Docker will sub-allocate /24 networks to individual Docker networks. When you create a Docker network, Docker will allocate a subnet for that network from one of the address pools.
  2. Each item in the array represents an address pool and has two properties: “base” and “size”.
  3. “base”:”″: This is the subnet that will be used as the pool of IP addresses for Docker networks. Docker will carve smaller subnets out of this pool and assign them to Docker networks as needed.
  4. “size”:24: This indicates the size of the subnets that Docker will carve out of the address pool. The number 24 means that each Docker network will be given a /24 subnet, which includes 256 IP addresses (however, some are reserved, so not all are usable).
  5. This configuration is useful if you want to control the IP address range that Docker uses for its networks, which can be necessary in certain networking or security scenarios. For example, you might want to avoid conflicts with other networks in your infrastructure.

Please note that this configuration has nothing to do with the DNS issue you mentioned earlier. If you need to specify a DNS server, you’d add a “dns” field to the JSON, like this:

   "default-address-pools": [{
   "dns": ["your_dns_address", ""]

Restart the docker and try again.

DNS resolution problem : Runner is unable to resolve the domain name ‘’
Git : Understanding the gitlab-ci.yml File in GitLab
Docker : Your authorization token has expired. Reauthenticate and try again – Solved
Docker : Docker not able to connect to git , what could be the reason ?
Docker : Error saving credentials: error storing credentials – err: exec: “docker-credential-ecr-login” – Solved

Author: user

Leave a Reply