How to access host port from docker container

前端 未结 14 1747
南旧
南旧 2020-11-22 03:41

I have a docker container running jenkins. As part of the build process, I need to access a web server that is run locally on the host machine. Is there a way the host web s

14条回答
  •  梦如初夏
    2020-11-22 03:46

    For me (Windows 10, Docker Engine v19.03.8) it was a mix of https://stackoverflow.com/a/43541732/7924573 and https://stackoverflow.com/a/50866007/7924573 .

    1. change the host/ip to host.docker.internal
      e.g.: LOGGER_URL = "http://host.docker.internal:8085/log"
    2. set the network_mode to bridge (if you want to maintain the port forwarding; if not use host):
      version: '3.7' services: server: build: . ports: - "5000:5000" network_mode: bridge or alternatively: Use --net="bridge" if you are not using docker-compose (similar to https://stackoverflow.com/a/48806927/7924573)
      As pointed out in previous answers: This should only be used in a local development environment.
      For more information read: https://docs.docker.com/compose/compose-file/#network_mode and https://docs.docker.com/docker-for-windows/networking/#use-cases-and-workarounds

提交回复
热议问题