search

Home  >  Q&A  >  body text

How to get the host IP in a docker container and connect to a service on the host

How to get the host IP in the docker container

For example, the nginx container may use the host's ruby ​​service

世界只因有你世界只因有你2783 days ago2786

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:19:24

    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

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:19:24

    1. Pass in docker run --env HOST_IP=192.168.0.160 through the environment variable and obtain

    through the environment variable $HOST_IP

    2. Bind the host when running dockerdocker run --network host,通过ip routeGet

    reply
    0
  • Cancelreply