Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker port forwarding not working

I have setup Docker container for access my machine docker container to another machine in local.

Create a container below command:

    docker run -it -d --name containerName -h www.myhost.net -v /var/www/html -p 7000:8000 --net mynetwork --ip 172.11.0.10 --privileged myimagename bash 

After Create A Container Details:

        CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES          1e1e5e9b74b4        myimgaename         "bash"              21 minutes ago      Up 6 minutes        0.0.0.0:7000->8000/tcp   containername 

NetWork Details:

     "NetworkSettings": {         "Bridge": "",         "SandboxID": "fe357c54c816fff0f9d642037dc9a173be7f7e42a80776d006572f6a1395969e",         "HairpinMode": false,         "LinkLocalIPv6Address": "",         "LinkLocalIPv6PrefixLen": 0,         "Ports": {             "8000/tcp": [                 {                     "HostIp": "0.0.0.0",                     "HostPort": "7000"                 }             ]         } 

if I access docker ipaddr(172.11.0.10) or hostname(www.myhost.net) in mymachine(hostmachine) it working

But if I access with Port doesn't work: hostmachine ip: 192.168.1.1

  go to the browser  192.168.1.1:7000  hostmachine and locally connected anoter machine also. 

But My 7000 port are listen in hostmachine:

        # ps aux | grep 7000         root     10437  0.0  0.2 194792 24572 pts/0    Sl+  12:33   0:00 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 7000 -container-ip 172.11.0.10 -container-port 8000         root     10941  0.0  0.0 118492  2324 pts/3    R+   12:44   0:00 grep --color=auto 7000 

update 1:

      $ docker version         Client:          Version:      1.11.2          API version:  1.23          Go version:   go1.5.4          Git commit:   b9f10c9          Built:        Wed Jun  1 21:39:21 2016          OS/Arch:      linux/amd64          Server:          Version:      1.11.2          API version:  1.23          Go version:   go1.5.4          Git commit:   b9f10c9          Built:        Wed Jun  1 21:39:21 2016          OS/Arch:      linux/amd64 

Suggest me Why Cannot access my Container to another machine. How to Resolve this Problem

like image 380
Rajkumar .E Avatar asked Sep 16 '16 07:09

Rajkumar .E


People also ask

How does port forwarding work in Docker?

Port mapping is used to access the services running inside a Docker container. We open a host port to give us access to a corresponding open port inside the Docker container. Then all the requests that are made to the host port can be redirected into the Docker container.

What does IP 0.0 0.0 mean Docker?

0.0:8080->80/tcp mapping. Docker, by default, added 0.0. 0.0 non-routable meta-address for the host. It means that the mapping is valid for all addresses/interfaces of the host.

How do I open ports in running Docker container?

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

Should I expose Docker port?

Some standard ports are 80 for webservers, 443 for webservers running over encryption (TLS/SSL), and 25 for mail. So when you want to allow applications to connect to your container, you need to expose one or more ports to the outside world.


1 Answers

A very common problem can be this:

Bind your app inside Docker to 0.0.0.0, not to 127.0.0.1 address to let Docker reach the app inside container.

like image 152
17 revs, 13 users 59% Avatar answered Sep 21 '22 00:09

17 revs, 13 users 59%