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

前端 未结 4 2201
隐瞒了意图╮
隐瞒了意图╮ 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 05:00

    Looks this issue does not seem to be so boring as it was. Followings docs at https://docs.docker.com/engine/reference/run/#expose-incoming-ports you can specify an IP address at the host machine where you want container's port(s) to be exposed.

    -p=[] : Publish a container's port or a range of ports to the host
                   format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
                   Both hostPort and containerPort can be specified as a
                   range of ports. When specifying ranges for both, the
                   number of container ports in the range must match the
                   number of host ports in the range, for example:
                       -p 1234-1236:1234-1236/tcp
                   When specifying a range for hostPort only, the
                   containerPort must not be a range.  In this case, the container port is published somewhere within the specified hostPort range. (e.g., `-p 1234-1236:1234/tcp`)
                   (use 'docker port' to see the actual mapping)
    

    Probably that is 127.0.0.1, and it resolves an issue with access to exposed Docker container port on the Windows system. Just use -p switch with IP address when running container.

    docker run --rm -it -p 127.0.0.1:3000:3000 ubuntu:latest
    

提交回复
热议问题