How to access docker container from another machin

2020-06-05 06:01发布

I'm using Docker for Windows( I am not using Docker Toolbox that use a VM) but I cannot see my container from another machine on local network. In my host everything is perfect and runs well,however, I want that other people use my container.

Despite being posting the same question in Docker's Forum , The answer was not show it. Plus, I have been looking for here but the solutions found it are about setting up the bridge option in the virtual machine , and as I said before, I am using Docker for windows that no use Virtual machine.

Docker version Command

Client:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 21:15:28 2016
 OS/Arch:      windows/amd64

Server:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 21:15:28 2016
 OS/Arch:      linux/amd64

docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                           NAMES
789d7bf48025        gogs/gogs           "docker/start.sh /bin"   5 days ago          Up 42 minutes       0.0.0.0:10022->22/tcp, 0.0.0.0:5656->3000/tcp   gogs
7fa7978996b8        mysql:5.7.14        "docker-entrypoint.sh"   5 days ago          Up 56 minutes       0.0.0.0:8989->3306/tcp                          mysql

The container I want to use is gogs that is working in the port 5656.

When I use localhost:5656 y 127.0.0.1:5656 work properly, but when I use My local network IP (192.168.0.127) from other machine the container is unreachable.

Thanks in advance.

2条回答
霸刀☆藐视天下
2楼-- · 2020-06-05 06:28

In Hyper-V settings, putting "Docker NAT" network in "external" mode worked for me. (I can access to my container on my local network with my host's IP)

查看更多
唯我独甜
3楼-- · 2020-06-05 06:31

Solution:

When I installed Docker for Windows, it creates a network called vEthernet (DockerNAT) (Usually with the ip 10.0.75.1)

My local machine had a network called local area connection with the ip 192.168.0.172(With this ip I was trying to access from other PCs).

So far, My local Machine had Two networks Conections so that I went to Control panel > NetWork and Sharing center > Change Adapter Settings I selected the two networks and I right-click selected Add to bridge. That create a Third network called Ethernet.

At this point, I didnt know what was the Ip of Ethernet network, so I executed ipconfig command that show me the ip 192.168.0.17(The settings of local area connection and vEthernet (DockerNAT) disappeared and the ips 10.0.75.1 and 192.168.0.172 stop working).

With this new ip (192.168.0.17) I tried from other machine in the network and finally I could access to the container(192.168.0.17:5656).

查看更多
登录 后发表回答