How to get the host IP in the docker container
For example, the nginx container may use the host's ruby service
The host uses loopback address aliases to solve this problem.
For example: add the alias IP 10.200.10.1 to the host's loopback address, and then use this IP in the container to connect to the host's service.
Configure local loopback address alias under MAC
1. Pass in docker run --env HOST_IP=192.168.0.160 through the environment variable and obtain
docker run --env HOST_IP=192.168.0.160
2. Bind the host when running dockerdocker run --network host,通过ip routeGet
docker run --network host
ip route
The host uses loopback address aliases to solve this problem.
For example: add the alias IP 10.200.10.1 to the host's loopback address, and then use this IP in the container to connect to the host's service.
Configure local loopback address alias under MAC
1. Pass in
through the environment variable $HOST_IPdocker run --env HOST_IP=192.168.0.160
through the environment variable and obtain2. Bind the host when running docker
docker run --network host
,通过ip route
Get