Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access docker container from another machine on local network

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.

like image 701
Carlos Andrés García Avatar asked Aug 23 '16 21:08

Carlos Andrés García


People also ask

How do I make my Docker container accessible from network?

To make a port available to services outside of Docker, or to Docker containers which are not connected to the container's network, use the --publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host to the outside world.

How do I run a Docker on a local network?

Use --network="host" in your docker run command, then 127.0. 0.1 in your docker container will point to your docker host. Note: This mode only works on Docker for Linux, per the documentation.

Can Docker containers access local network?

Your host can still be accessed from containers in the default bridge networking mode. You just need to reference it by its Docker network IP, instead of localhost or 127.0. 0.1 .

How do you access a container from the outside?

If you run container with -p 80:8080, you'll be able to access in-container web server running on port 8080 from outside world, querying port 80 on docker host. You received this message because you are subscribed to the Google Groups "docker-dev" group.


2 Answers

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).

like image 61
Carlos Andrés García Avatar answered Oct 31 '22 20:10

Carlos Andrés García


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)

like image 45
Mickaël B. Avatar answered Oct 31 '22 22:10

Mickaël B.