# Run cannot assign requested address

**URL:** <https://forums.docker.com/t/run-cannot-assign-requested-address/24293>\
**Category:** General\
**Created:** [November 3, 2016, 8:20am UTC](https://forums.docker.com/t/run-cannot-assign-requested-address/24293 "2016-11-03T08:20:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lachele](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@lachele](https://forums.docker.com/u/lachele)\
**Post date:** [November 3, 2016, 8:20am UTC](https://forums.docker.com/t/run-cannot-assign-requested-address/24293/1 "2016-11-03T08:20:43Z")

</div>

**Issue type:** Can’t start container with desired networking. Before I continue endlessly trouble-shooting, I’m hoping someone might just see the problem. I will happily accept referral to the appropriate docs (I have tried to find them). If it shouldn’t have ever worked, please help me see how to do something equivalent.

I want to be able to have only the container assigned to a certain IP address and port combination.

**OS Version/build:** Debian 8.5 and Ubuntu 14.04.5, at least

**Docker versions:** 1.11.2, build b9f10c9 & 1.12.3, build 6b644ec

**App version:** Complicated homemade thing, but can reproduce on others. See below.

**Steps to reproduce:** Try to use “-p 192.168.x.y:Z:Z” in a docker run command. I’m not sure how to make it always work or not work.

**Expected behavior** that I got to work at least once: queries to port Z at IP address 192.168.x.y are sent to the container.

**Sometimes it works:**

For example here: [http://dev.glycam.org](http://dev.glycam.org)

- The docker version is 1.11.2, build b9f10c9
- The host is Debian 8.5
- I don’t think the host machine has any other relationship to the ip address, as in:  
\*\* There is no host interface, real virtual or other, with the address 192.168.x.y.  
\*\* Neither is the address listed in our internal DNS.
- Our router does NAT the external address to that one. Could this somehow be the difference?
- Attempts to start other images in analogous manners on the same host give errors as detailed below.  
\*\* For example, I can’t get this to work at all: `docker run -dit --name my-apache-app -p 192.168.x.y:80:80 -v "$PWD/htdocs/":/usr/local/apache2/htdocs/ httpd:2.4`

Here’s how I start the container for the site above:  
` docker run \ -d -P \ -p 192.168.x.y:80:80 \ --net=DOCKER_NETWORK \ --name NET_NAME \ --net-alias NET_ALIAS \ -v $(pwd)/directory1:/path1/in/container \ -v $(pwd)/directory2:/path2/in/container \ -v $(pwd)/directory3:/path3/in/container \ image_name:image_tag`

I stopped and restarted that container tonight to prove that the command still works.

Is there some way to figure out what I did right in this case that I’m not doing in others?

**Mostly, it doesn’t work:**

I think I’m doing things the same, so there must be something subtle that I’m not seeing. When it doesn’t work, the response is always something like:

`docker: Error response from daemon: driver failed programming external connectivity on endpoint my-apache-app (longhash): Error starting userland proxy: listen tcp 192.168.x.y:80: bind: cannot assign requested address.`

I haven’t yet duplicated exactly the website (above, that works) elsewhere. Doing that isn’t as simple as you might think. But, I can. Probably.

**This has been addressed before.** See forum links below. I’ve also found discussion on GitHub. But, I can’t find any resolutions that explain the issue or fix the problem for me. Some of the posts below are under “for mac” or “for windows”, but I’m not convinced that it is an OS thing.

> [@Issues binding IP ports through -p](https://forums.docker.com/t/issues-binding-ip-ports-through-p/2380/2):
>
> Greetings, I will add a virtual interface on the host that has a different IP address than the primary ifconfig eth0:1 10.2.0.50 netmask 255.255.255.0 up

> [@IP Address aliasing?](https://forums.docker.com/t/ip-address-aliasing/16195):
>
> Expected behavior docker run -d --name cb1 -p 10.0.75.2:8091:8091 couchbase docker run -d --name cb2 -p 10.0.75.3:8091:8091 couchbase I would expect this to create two containers that I can access with different IP addresses that have the same port numbers exposed. Actual behavior The first command works fine: PS C:\WINDOWS\system32\> docker run -d --name cb1 -p 10.0.75.2:8091:8091 couchbase d8ea41a0b900bb1d164bf0ba5e88a52edf99000a46b95d50002769cd48a33836 But the second one (cb2 above) I ge…

> [@Bind: cannot assign requested address](https://forums.docker.com/t/bind-cannot-assign-requested-address/12230):
>
> Expected behavior A container port gets bound to the specified ip:port . I should be able to specified any available ip adress on my interfaces, e.g. ip of my local network connection, or an arbitrary alias created for the loopback interface. Actual behavior An error is displayed: Error starting userland proxy: listen tcp 192.168.0.3: 11212: bind: cannot assign requested address. Information pinata diagnose -u on OSX OS X: version 10.10.5 (build: 14F1713) Docker.app: version v1.11.1-beta11 Ru…

> [@DFM: Docker network created, can't bind to assigned endpoint](https://forums.docker.com/t/dfm-docker-network-created-cant-bind-to-assigned-endpoint/17478):
>
> Having a difficult time understanding my error. Steps to create: $ docker network create --subnet=10.1.1.0/24 etcd-net $ docker network ls NETWORK ID NAME DRIVER SCOPE 80fa859ef3ae bridge bridge local 0a21d6f16194 etcd-net bridge local 65e54b9b8fbd host host local a22129f9c0a0 none null local $ docker run -d --net e…

> [@Multiple Host Lan Connections](https://forums.docker.com/t/multiple-host-lan-connections/12922):
>
> Is it possible to setup multiple lan ip connections with docker for mac? as you can do you can do on linux… Example… I would like to run two containers running on specific ip addresses coming into my mac via the host lan docker run --detach --publish 192.168.1.230:80:80 --restart always -i -t tutum/hello-world; docker run --detach --publish 192.168.1.231:80:80 --restart always -i -t tutum/hello-world; However I get this error, docker: Error response from daemon: driver failed programming ex…

> [@Container fails to start "Cannot assign requested address"](https://forums.docker.com/t/container-fails-to-start-cannot-assign-requested-address/9302):
>
> Expected behavior Container starts. Actual behavior Container fails to start, the output is: WARNING: Logging before InitGoogleLogging() is written to STDERR F0416 02:44:14.481470 1 process.cpp:889] Failed to initialize: Failed to bind on 192.168.1.2:5050: Cannot assign requested address: Cannot assign requested address [99] \*\*\* Check failure stack trace: \*\*\* note No other process is operating on port 5050. Information OS X: version 10.11.3 (build: 15D21) Docker.app: version v1.11.0-beta…

---

<div class="post-metadata">

**Author:** ![dmaze](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@dmaze](https://forums.docker.com/u/dmaze)\
**Post date:** [November 3, 2016, 11:19am UTC](https://forums.docker.com/t/run-cannot-assign-requested-address/24293/2 "2016-11-03T11:19:34Z")

</div>

> [@lachele](#):
>
> I can’t get this to work at all: `docker run -dit --name my-apache-app -p 192.168.x.y:80:80 -v "$PWD/htdocs/":/usr/local/apache2/htdocs/ httpd:2.4`
> 
> There is no host interface, real virtual or other, with the address 192.168.x.y.
> 
> `docker: Error response from daemon: driver failed programming external connectivity on endpoint my-apache-app (longhash): Error starting userland proxy: listen tcp 192.168.x.y:80: bind: cannot assign requested address.`

The second thing I quoted causes the third thing.

At a higher level, what are you trying to do, and what’s your end goal? If, as you say, the host system doesn’t have an interface listening on 192.168.x.y, then even if Docker could successfully **bind** (2), it would be totally ineffectual: the host system can never receive packets on that address, so nothing will ever get sent on to the container.

> [@](#):
>
> Our router does NAT the external address to that one. Could this somehow be the difference?

Is your network topology something like so:

```auto
  192.168.x.y +--------+ 10.20.30.1 +-----------------+
<------------ | Router | -------------- | Host +--------+ |
              +--------+ 10.20.30.2 | | Docker | |
                                        | +--------+ |
                                        +-----------------+

```

If the host only has a single network interface and your network setup is reasonable, you don’t need the “address” part of the `docker run -p` option at all. This will cause all inbound packets to the system (including, in my example, the 10.20.30.2/24 private network) on the right port to get forwarded from your container. Your router, on a separate system, is listening on 192.168.x.y (which is what you want) and does reverse NAT to send that port’s traffic to the right place on the internal network.

---

<div class="post-metadata">

**Author:** ![lachele](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@lachele](https://forums.docker.com/u/lachele)\
**Post date:** [November 3, 2016, 9:32pm UTC](https://forums.docker.com/t/run-cannot-assign-requested-address/24293/3 "2016-11-03T21:32:14Z")

</div>

Thanks for the quick reply!

I believe you are saying that this is the problem.

> There is no host interface, real virtual or other, with the address 192.168.x.y.

But, this is the situation on the machine where it **works**. This is also the way I want it (more on that below). _From the future (see below): EXCEPT that I was totally wrong about this. So, this post is about how I wish it worked… Sorry for any confusion._

It is also the situation where it doesn’t work.

The network topology on one host that works **and** one that doesn’t, by design and appearance, if not always behavior, is:

Here:  
192.168.x.R – The internal IP address of the gateway/router  
192.168.x.H – The IP address of the host on interface if0  
192.168.x.D – The intended IP address of the docker container  
The ‘bridge’ is ideally an isolated network created for the container, but I’ve tried different permutations in the course of trouble-shooting.

```
  Public IP +----------------------+
    WAN | Host |
     | | +--------+ |
     V | |--------| bridge | |
 +--------+ 192.168.x.R +---+ +--------+ |
 | Router | ----------------- |if0| | |
 | | 192.168.x.H +---+ | |
 | NAT | | | |
 | Pub IP | | +-------------+ |
 | to | | | Docker | |
 | .x.D | | + 192.168.x.D + |
 +--------+ | +-------------+ |
                              +----------------------+

```

What I’m hoping for is that the host won’t have that IP address or answer to it in any way except to forward approved packets to the container.

However, in the instance that works, it does appear that docker has somehow assigned 192.168.x.D to the host, but the host seems unaware of it (per ifconfig and iptables). That is, I can ssh to 192.168.x.D and I get logged into 192.168.x.H, but I don’t want that to happen. The container can’t accept ssh. I don’t want the container’s IP to make it possible to otherwise access the host.

I can almost certainly make a lot of this happen by hand using IPtables, but I had gotten rather excited by the fact that Docker did it automagically, at least in one case, and I’d be very happy if it did it more often.

---

<div class="post-metadata">

**Author:** ![lachele](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@lachele](https://forums.docker.com/u/lachele)\
**Post date:** [November 5, 2016, 3:31am UTC](https://forums.docker.com/t/run-cannot-assign-requested-address/24293/4 "2016-11-05T03:31:04Z")

</div>

I really think this should work. VirtualBox does a similar thing with a bridge that always seems to work just fine. And, it has worked at least once with Docker. I do eventually plan to use swarm mode, but only in production: I’d like to use this simpler mechanism for our development environment.

I looked at the threads on GitHub, but they get lengthy and sometimes off-topic, and I kept getting lost in them. Whatever I found that might be a solution didn’t fix my problem.

Maybe I’ll try making a bug report if no one responds soon. To get work done in the meantime, I’ll brush up on IPTables, maybe even check the source code.

---

<div class="post-metadata">

**Author:** ![lachele](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@lachele](https://forums.docker.com/u/lachele)\
**Post date:** [November 8, 2016, 5:53am UTC](https://forums.docker.com/t/run-cannot-assign-requested-address/24293/5 "2016-11-08T05:53:16Z")

</div>

OK… I had set up an extra IP address on if0 in the diagram above. I found that using “ip a list if0”. I even had that in my notes but missed it entirely somehow. So, I take back the bits about it working without that (and will edit above to that effect).

But, I still prefer not to have to do that. I would rather that the container - or, better, an isolated docker network - have exclusive access to the IP address so that it could not be used to access the host.
