Docker Desktop for Windows: cannot access service on exposed port in windows container mode

前端 未结 4 2203
隐瞒了意图╮
隐瞒了意图╮ 2021-02-19 04:09

I am using the following Dockerfiles to create a container running Jenkins in a windows container on Windows 10 desktop running Docker Desktop for Windo

4条回答
  •  逝去的感伤
    2021-02-19 04:45

    To complete @Kallie-Microsoft post:

    docs.docker.com have been updated with a section Limitations of Windows containers for localhost and published ports


    Docker for Windows provides the option to switch Windows and Linux containers. If you are using Windows containers, keep in mind that there are some limitations with regard to networking due to the current implementation of Windows NAT (WinNAT). These limitations may potentially resolve as the Windows containers project evolves.

    One thing you may encounter rather immediately is that published ports on Windows containers do not do loopback to the local host. Instead, container endpoints are only reachable from the host using the container’s IP and port.

    So, in a scenario where you use Docker to pull an image and run a webserver with a command like this:

    docker run -d -p 80:80 --name webserver nginx
    

    Using curl http://localhost, or pointing your web browser at http://localhost will not display the nginx web page (as it would do with Linux containers).

    In order to reach a Windows container from the local host, you need to specify the IP address and port for the container that is running the service.

    You can get the container IP address by using docker inspect with some --format options and the ID or name of the container. For the example above, the command would look like this, using the name we gave to the container (webserver) instead of the container ID:

    $ docker inspect \
      --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \
      webserver
    

提交回复
热议问题