Search code examples
dockerhyper-v

How do I access a Docker container running in a Hyper-V VM from an external machine?


For $REASONS, I am trying to spin up a Docker image in a Hyper-V VM that is part of a failover cluster. In pictures, that looks like this (each component will be labeled with a name that I will hereafter use to describe that component):

------------------------------------------
| Physical failover cluster              |
| (hypervisor)                           |
|  ------------------------------------  |
|  | Hyper-V VM with Docker installed |  |
|  | (docker-host)                    |  |
|  |  --------------------            |  |
|  |  | Docker container |            |  |
|  |  | (container)      |            |  |
|  |  |                  |            |  |
|  |  --------------------            |  |
|  |                                  |  |
|  ------------------------------------  |
|                                        |
------------------------------------------

(Yes, I know this is a dumb idea; no, that is not the question. The question is whether I can make the dumb idea show some semblance of working like I want it to.)

I've got docker-container running properly on docker-host, and if I fire up a web browser on docker-host, I can access the server running in docker-container. However, I cannot access the Docker server from any other machine.

I have tried the following:

  • Passing all of these -p argument strings to Docker (n.b. this app is running over HTTP at the moment, so port 443 shouldn't matter):
    • -p 80:80
    • -p 80:80 -p 443:443
    • -p 0.0.0.0:80:80
    • -p 127.0.0.1:80:80
  • Adding a network adapter to the Hyper-V image that was spun up on docker-host.
  • Reading every StackOverflow post (and other sites as well) that seems to relate to this issue.

If necessary, I may be able to move the Docker container run on hypervisor instead of docker-host. However, I'd like to know if I can salvage what I've got so far.


Solution

  • I've got it working now. It turns out you have to open Windows Firewall settings and allow C:\Program Files\Docker\Docker\resources\com.docker.backend.exe through the firewall. After that, plus a little nginx-proxy-manager magic to handle URL proxying properly, it all works great!

    Thanks to @NickODell for pointing out the firewall as a culprit!