How can the docker container communicate host machine?

1.8k Views Asked by At

Host machine ip:192.168.123.2 Gateway:192.168.123.1

Adapter is enp3s0, so I create a docker network in host:

docker network create -d macvlan --subnet 192.168.123.0/24 --gateway 192.168.123.1 -o parent=enp3s0 -o macvlan_mode=bridge macnet

Run a container set IP

docker run --net macnet --ip 192.168.123.102 --name hd3  -it  ubuntu bash

Container and Host machine ping Gateway 192.168.123.1 are all work.
But doesn't work between the container and the host.

Container:
ping Gateway is OK
ping Host isn't OK

Host:
ping Gateway is OK
ping Container isn't OK

Why and How can I communicate between the docker container and host machine?

1

There are 1 best solutions below

0
On

If you have a recent enough docker (18.03 and more), see, as mentioned here, if you can use:

host.docker.internal

That was first documented for MacOS as host, but should work on Windows host too.