fussybeaver / bollard

Docker daemon API in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Equivalent of `--add-host=host.docker.internal:host-gateway`

banool opened this issue · comments

On Docker for Desktop on MacOS and Windows you can use host.docker.internal to access localhost on the host system. On newer versions of Docker on Linux this is also possible, but it doesn't work out of the box, you have to use --add-host=host.docker.internal:host-gateway.

I wonder, how do you do this Bollard? I have tried this:

host_config.extra_hosts = Some(vec!["host.docker.internal:host-gateway".to_string()]);

I see this issue brought up the topic, but in this case it wasn't anything to do with Bollard: #324.

Oop turns out this actually worked! Looking at docker inspect, this does the exact same thing as the CLI flag:

            "ExtraHosts": [
                "host.docker.internal:host-gateway"
            ],