Jump to content
dlandon

IP address assignment to Docker containers

63 posts in this topic Last Reply

Recommended Posts

I'm not clear on the IP address assignment to a docker.  I want to assign the static IP address 192.168.1.8 to my ownCloud docker.  How do I go about doing that?  How does the docker pick up that IP address?

Share this post


Link to post
5 minutes ago, dlandon said:

I'm not clear on the IP address assignment to a docker.  I want to assign the static IP address 192.168.1.8 to my ownCloud docker.  How do I go about doing that?  How does the docker pick up that IP address?

 

Change Network Type of a container to a custom network, e.g. eth0 or br0

 

A new field Fixed IP address (optional) appears and allows you to assign a fixed address

Share this post


Link to post
32 minutes ago, bonienl said:

 

Change Network Type of a container to a custom network, e.g. eth0 or br0

 

A new field Fixed IP address (optional) appears and allows you to assign a fixed address

Now that is slick!

Share this post


Link to post
1 hour ago, bonienl said:

 

Change Network Type of a container to a custom network, e.g. eth0 or br0

 

A new field Fixed IP address (optional) appears and allows you to assign a fixed address

 

I don't get this option. Only "None", "Bridge" or "Host" (basically the same as before). Will the "Custom" option only show under specific conditions?

Share this post


Link to post

Did you stop the container before trying.

 

Kevin

16 minutes ago, billington.mark said:

 

I don't get this option. Only "None", "Bridge" or "Host" (basically the same as before). Will the "Custom" option only show under specific conditions?

 

Share this post


Link to post
1 minute ago, digitalfixer said:

Did you stop the container before trying.

 

Kevin

 

 

I have indeed. I also only get  "None", "Bridge" or "Host" as network options on new containers as well.

Share this post


Link to post
1 minute ago, billington.mark said:

 

I have indeed. I also only get  "None", "Bridge" or "Host" as network options on new containers as well.

 

It definitely works, I just tried it on one of my containers and br0 was at the bottom of the list.

The only other thing that comes to mind is, do you bridging enabled in network settings.

If that doesn't fix it then one of the more knowledgable people will have the answer I'm sure.

 

Kevin

Share this post


Link to post
1 minute ago, digitalfixer said:

 

It definitely works, I just tried it on one of my containers and br0 was at the bottom of the list.

The only other thing that comes to mind is, do you bridging enabled in network settings.

If that doesn't fix it then one of the more knowledgable people will have the answer I'm sure.

 

Kevin

 

Bridging is enabled and br0 is definitely available. (im posting from a VM using that bridge!) 

 

Share this post


Link to post
8 minutes ago, billington.mark said:

 

Bridging is enabled and br0 is definitely available. (im posting from a VM using that bridge!) 

 

 

br0 must have an IP address either static or by DHCP

Share this post


Link to post
36 minutes ago, digitalfixer said:

Did you stop the container before trying.

 

Kevin

 

I did this without stopping the docker container.

Share this post


Link to post
42 minutes ago, digitalfixer said:

Did you stop the container before trying.

 

Kevin

 

Custom networks are only added when the Docker service itself is started. Stopping and starting a container has no effect.

 

Share this post


Link to post
37 minutes ago, bonienl said:

 

br0 must have an IP address either static or by DHCP

 

FIXED.

Restarted the docker service via the GUI and now i have the option. 

 

Only thing i can think is that because im running my router (pfsense) as a vm, br0 has no IP assigned when the docker service starts and only gets it after my pfsense VM is up and running.

 

 

 

Share this post


Link to post

How do I get an IPV6 address on a docker without manually assigning one?

Share this post


Link to post
44 minutes ago, dlandon said:

How do I get an IPV6 address on a docker without manually assigning one?

 

When the custom network (br0 or eth0) has an IPv6 address assigned then the docker container will get automatically an IPv6 address out of the same subnet. The IPAM functionality of docker will assign the ::1 address as gateway address, you will need to set that address on your router if you want the container to go outside of your LAN.

Share this post


Link to post

when i give a docker container an ip (network set to br0), other containers, which are still set to network mode bridge, can't connect to the first one.

 

example:

the plex container is set to ip 192.168.0.20

the plexpy container is set to bride (running on unraid on ip 192.168.0.15).

 

in this case, plexpy can't connect to plex on the set ip.

 

I'm guessing there are some routing-problems.

 

other thing: I've noticed, that everytime i changed something in the container (would possibly happen on an update, too), the container gets a new MAC id. This can lead to loosing port forwarding rules set for that container in the router. (in my case, the computer to forward the port to is selected via MAC and not IP, since the IP could change on DHCP devices)

Edited by Benni-chan

Share this post


Link to post
11 minutes ago, Benni-chan said:

when i give a docker container an ip (network set to br0), other containers, which are still set to network mode bridge, can't connect to the first one.

 

example:

the plex container is set to ip 192.168.0.20

the plexpy container is set to bride (running on unraid on ip 192.168.0.15).

 

in this case, plexpy can't connect to plex on the set ip.

 

I'm guessing there are some routing-problems.

 

other thing: I've noticed, that everytime i changed something in the container (would possibly happen on an update, too), the container gets a new MAC id. This can lead to loosing port forwarding rules set for that container in the router. (in my case, the computer to forward the port to is selected via MAC and not IP, since the IP could change on DHCP devices)

For containers to communicate they need to be on the same interface like br0.

Share this post


Link to post
On 6/5/2017 at 7:28 AM, bonienl said:

br0 must have an IP address either static or by DHCP

There's a use case for the host not having an IP address on a bridge.  A second nic connecting the wan interface of a firewall docker or vm to the outside world is a good example.

 

Its also useful at times to have a bridge with no host interface.  An example is a test environment where Dockers and/or VMs can talk, with no access to the outside world.  I needed to start a Windows VM with no network access.  Since I couldn't find a way to disable the virtual nic, I created a bridge with no interface, and edited the XML file to access this bridge.

Share this post


Link to post
1 hour ago, Porkie said:

For containers to communicate they need to be on the same interface like br0.

Correct Docker treats "bridge" as a single network and containers set up in bridge mode are all in the same network. A container in a custom network, e.g. br0 is a different network to Docker.

 

Share this post


Link to post
1 hour ago, aim60 said:

There's a use case for the host not having an IP address on a bridge.  A second nic connecting the wan interface of a firewall docker or vm to the outside world is a good example.

 

Its also useful at times to have a bridge with no host interface.  An example is a test environment where Dockers and/or VMs can talk, with no access to the outside world.  I needed to start a Windows VM with no network access.  Since I couldn't find a way to disable the virtual nic, I created a bridge with no interface, and edited the XML file to access this bridge.

 

The "problem" with interfaces without an IP assignment is that no automatic settings can be propagated to Docker as it is unknown what to assign.

 

Share this post


Link to post
1 hour ago, Benni-chan said:

other thing: I've noticed, that everytime i changed something in the container (would possibly happen on an update, too), the container gets a new MAC id. This can lead to loosing port forwarding rules set for that container in the router. (in my case, the computer to forward the port to is selected via MAC and not IP, since the IP could change on DHCP devices)

 

With custom networks you have the possibility to set a fixed IP address for the container. Forwarding rules on your firewall can refer to this IP address.

Share this post


Link to post
2 minutes ago, bonienl said:

 

With custom networks you have the possibility to set a fixed IP address for the container. Forwarding rules on your firewall can refer to this IP address.

This is exactly what I am doing for ownCloud, MineOS, and Zoneminder dockers so they are accessible from the internet.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.