0

Hello I have following dockerfile on my macOS Sierr High (as example):

FROM richarvey/nginx-php-fpm:1.3.7
EXPOSE 80

And I'm able to build and run it on 192.168.8.101:8082 by

docker build -t myproject
docker run -d -p 192.168.8.101:8082:80 --name myproject myproject

and it works on http://192.168.8.101:8082 my local computer and devices (iPhone) connected to the same wifi network (I also have no problem to run container on localhost).

However when I try tu run this container on other IP like for example 192.168.8.102:8082 I get following error:

Mac-mini-Kamil:myproject Kamil$ docker run -d -p 192.168.8.102:8082:80 --name myproject myproject 
f939d38243f420f812c859f5fe275faf49dc6e123d807583ec240fbdf0619a17 
docker: Error response from daemon: driver failed programming external connectivity on endpoint myproject (0b546e63887e3ddeb4d2b21a8d6d15a94e33f1ff67c2765174a808bf6b13e120): Error starting userland proxy: listen tcp 192.168.8.102:8082: bind: cannot assign requested address.

I try also other addresses like 172.17.1.2 but with no success and I don't have idea why. Do someone cane give me advice (and/or instruction about what more information I should provide to this question to solve it) ? I would like to know: why I cannot use other IPs and what I can do to use other IPs?

UPDATE - additional informations:

After execute ifconfig I selected two interesting results :

en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether a8:8e:24:a3:d3:91 
    inet6 fe80::18fe:1146:6389:b630%en1 prefixlen 64 secured scopeid 0xa 
    inet 192.168.8.101 netmask 0xffffff00 broadcast 192.168.8.255
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect
    status: active

bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=63<RXCSUM,TXCSUM,TSO4,TSO6>
    ether 32:00:11:fc:70:40 
    Configuration:
        id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
        maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
        root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
        ipfilter disabled flags 0x2
    member: en2 flags=3<LEARNING,DISCOVER>
            ifmaxaddr 0 port 9 priority 0 path cost 0
    nd6 options=201<PERFORMNUD,DAD>
    media: <unknown type>
    status: inactive
Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345
  • What is your ipv4 when you check it with ipconfig or ifconfig? Error response from daemon: driver failed programming external connectivity on endpoint: = If it's not your IP you can not connect with it – lvthillo Jan 04 '18 at 14:53
  • I believe it is because you have to first add the ip: `192.168.8.102` to your host's interface and then `run` the container, as it is suggested here: [Giving a docker container a routable ip address](https://stackoverflow.com/questions/26539727/giving-a-docker-container-a-routable-ip-address) – tgogos Jan 04 '18 at 14:59
  • @tgogos - no I not add the ip - but may be i have some 'strange' settings in my machine - how i can check this? – Kamil Kiełczewski Jan 04 '18 at 15:02
  • @Ivthillo I update my answer. – Kamil Kiełczewski Jan 04 '18 at 15:03
  • Take a look to https://docs.docker.com/engine/userguide/networking/#default-networks. Usually docker protects to access from other docker containers. – Rubén Pozo Jan 04 '18 at 15:04
  • @tgogos i update my answert - and in ifconfig i see my `en1: inet 192.168.8.101` - but what next? (Im unable to use command `ip addr` becouse I work on macOs) – Kamil Kiełczewski Jan 04 '18 at 15:24
  • @lvthillo you have right - secret is discover - this works because 192.168.8.101 was my computer IP in local wifi network . Please write down your comment as answer and I will 'check' it. – Kamil Kiełczewski Jan 04 '18 at 15:37

2 Answers2

2

The output of ifconfig (linux, OSX) or ipconfig (Windows) will probably tell you that your IP4 is 192.168.8.101.

That's reason why 192.168.8.101:8082:80 works. Docker can access the endpoint and can map port 80 of its container on port 8082 of 192.169.8.101.

When you use another IP this error will pop up:

Error response from daemon: driver failed programming external connectivity on endpoint

This means your Docker daemon can not access the endpoint 192.168.8.102 which is logical because it isn't the IPV4 address of your machine.

The bridge0 network is the default Docker network. If you don't specify a network your Docker container will be deployed inside this network.

You can do: docker inspect network bridge The output of this command will return a subnet like "Subnet": "172.17.0.0/16". Every container will have an IP between this private range.

What you are actually doing is mapping 172.17.X.X:80 on 192.168.8.101:8082 which works when 192.168.8.101 is accessible from you machine.

lvthillo
  • 28,263
  • 13
  • 94
  • 127
0

i suspect that your previous container still using port 8082 try using another port. . i dont know how to check used port in mac but if its in linux you can check your open port with netstat -ntlp

Fendi jatmiko
  • 2,567
  • 1
  • 9
  • 15