Docker on Windows: how to connect to container from host using container IP?

前端 未结 2 1779
时光说笑
时光说笑 2020-12-16 02:46

I have

  • Windows 10
  • Docker for Windows V. 1.12.5 Rev. 9503, which does not rely on boot2docker or VirtualBox anymore.

I have a number of

相关标签:
2条回答
  • 2020-12-16 02:53

    you can't. docker is not a virtual machine, and you don't get access to the docker host via IP address.

    see my same question here: https://forums.docker.com/t/access-dockerized-services-via-the-containers-ip-address/21151

    and my realization of how this works, here: https://derickbailey.com/2016/08/29/so-youre-saying-docker-isnt-a-virtual-machine/

    if you need to use the app hosted in the container, from your localhost, expose the port of the app with the -p option of docker run

    docker run -p 8080:8080 image_name

    and then connect to localhost:8080 for that service

    0 讨论(0)
  • 2020-12-16 02:59

    On docker for windows you can use address 10.0.75.1:8080 but you need to configure your firewall, a better way is using address 10.0.75.2:8080,

    for both addresses you have to publish your port when you run container

    docker run -p 8080:8080 image_name
    

    More info https://github.com/docker/for-win/issues/334#issuecomment-297030101

    0 讨论(0)
提交回复
热议问题