# How to get the IP address of the docker host from inside a docker container?

To get the IP address of the Docker host from inside a Docker container, you can use the `docker.for.mac.localhost` hostname. This hostname resolves to the IP address of the Docker host when used from inside a Docker container on a Mac.

Here's an example of how you can get the IP address of the Docker host from inside a Docker container:

1. Run the following command to start a Docker container:
    
    ```bash
    docker run -it alpine /bin/sh
    ```
    
    This will start a new Docker container based on the Alpine Linux image and open an interactive shell inside the container.
    
2. Once inside the container, run the following command to get the IP address of the Docker host:
    
    ```bash
    ping docker.for.mac.localhost
    ```
    
    This will send a ping request to the **`docker.for.mac.localhost`** hostname, which will resolve to the IP address of the Docker host.
    
    Alternatively, you can run the following command to get the IP address directly:
    
    ```bash
    ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}'
    ```
    
    This command uses **`ifconfig`** to get a list of network interfaces and their IP addresses, then uses **`grep`** and **`awk`** to filter out the loopback address (**`127.0.0.1`**) and print the IP address of the first non-loopback interface. This should be the IP address of the Docker host.

[ad-logs]