# Using secondery IP for docker

**URL:** <https://forums.docker.com/t/using-secondery-ip-for-docker/93485>\
**Category:** General\
**Created:** [May 2, 2020, 11:18pm UTC](https://forums.docker.com/t/using-secondery-ip-for-docker/93485 "2020-05-02T23:18:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![funkytwig](https://avatars.discourse-cdn.com/v4/letter/f/a88e57/32.png) [@funkytwig](https://forums.docker.com/u/funkytwig)\
**Post date:** [May 2, 2020, 11:18pm UTC](https://forums.docker.com/t/using-secondery-ip-for-docker/93485/1 "2020-05-02T23:18:26Z")

</div>

Hi, Ime trying to get our company to start using docker and as the main IP for our production server is being used (its managed via virtualmin) I got us a second IP for docker stuff and am trying to work out how to get docker containers to use it.

A lot of googling has kind of helped but I think the dest thing to do is set the IP for the network so when I do

`docker network create nginx-proxy`

Can I specify which IP address for it to use? Looking at the docs I see --ip-range` but nothing to specify a specific IP. Can I just do something like

`docker network create --ip-range=x.x.x.x nginx-proxy`

The main IP address is enp7s0 and the secondary one is enp7s0:0, they are both bound to the same NIC.

Regards,  
Ben

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [May 3, 2020, 11:27am UTC](https://forums.docker.com/t/using-secondery-ip-for-docker/93485/2 "2020-05-03T11:27:45Z")

</div>

It is not possible to assign a host ip to container.  
Though, for plain docker containers you can bind published ports to a host ip, if you use the port mapping like this `-p host_ip:host_port:container_port`, the same syntax can be used with docker-compose. For swarm service containers the option does not exist.

---

<div class="post-metadata">

**Author:** ![funkytwig](https://avatars.discourse-cdn.com/v4/letter/f/a88e57/32.png) [@funkytwig](https://forums.docker.com/u/funkytwig)\
**Post date:** [May 3, 2020, 12:16pm UTC](https://forums.docker.com/t/using-secondery-ip-for-docker/93485/3 "2020-05-03T12:16:45Z")

</div>

Ime not trying to assign it to a container, ime trying to get the whole of docker, or a docker network, to not use the primary IP. I have got a second IP for the server and I want ot use it for docker.

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [May 4, 2020, 5:33am UTC](https://forums.docker.com/t/using-secondery-ip-for-docker/93485/4 "2020-05-04T05:33:14Z")

</div>

Please try the forum search with the keywords “mavclan” and “ipvlan” and check if this is what you want. .

I am not going to give any advice on those aproaches, as I believe they are unnecessary - I ran dozens of swarm environment in production and NEVER had to use either one of both. Published ports on containers in (docker) overlay or bridged networks are sufficient for most usecases.

---

<div class="post-metadata">

**Author:** ![funkytwig](https://avatars.discourse-cdn.com/v4/letter/f/a88e57/32.png) [@funkytwig](https://forums.docker.com/u/funkytwig)\
**Post date:** [May 7, 2020, 11:45pm UTC](https://forums.docker.com/t/using-secondery-ip-for-docker/93485/5 "2020-05-07T23:45:51Z")

</div>

Thanks, did a search on mavclan and got one hit, this thread. Anyway think I found a solution

iptables -t nat -I POSTROUTING -p all -s 172.17.0.0/16 -j SNAT --to-source 5.6.7.8

Does this seem sensible. As you say mavclan/ipvlan are unnecessary maybe the above is a good solution?

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [May 8, 2020, 4:41am UTC](https://forums.docker.com/t/using-secondery-ip-for-docker/93485/6 "2020-05-08T04:41:55Z")

</div>

> [@funkytwig](#):
>
> , did a search on mavclan and got one hit, this thread

😊 my bad, it should have been macvlan and not mavclan.

Someone else need to respond to the iptables rule. Never needed to modify for docker in the past 5 years.
