guys! I'm very need your help! What I must to do(step-by-step), for correct creation of the network interface, for Docker, with my own subnet(192.168.0.0/24)? When I'm trying to create it, my hole network going down or incorrect network interface come back after docker's restart! Can't escape of it!
-
What are you trying to accomplish? You want the container to run on your home/work network? Or is this a new network just for your containers?– Esteban GarciaJan 17, 2018 at 20:40
-
@EstebanGarcia I want use them in my local existing network, I have host server, but now I wanna practice in VmwareWorkstation, before installing docker on the host server– StefanJan 17, 2018 at 20:55
1 Answer
Based on your comments I think I understand what you need. You want to have multiple container in your host each with a unique IP address from your host network.
Now, I haven't test this but this is what you should do:
Remove the IP Address from your host network interface
$ sudo ip addr del <IP>/24 dev <interface_name>
Create a docker network using a bridge to your host interface
$ sudo docker network create --driver bridge --subnet=<your_subnet>/24 --gateway=<here_the_ip_you_deleted_before> --opt "com.docker.network.bridge.name"="docker1" net_name
Add the interface to the just created bridge
$ sudo brctl addif docker1 <interface_name>
Now you can create a container, attach it to the created network and assign an IP from your subnet to it.
$ docker run --net net_name --ip <ip_you_want> -ti ubuntu:16.04
-
but if I want for example install web-server and databases.. I need unique ip address for this things– StefanJan 17, 2018 at 21:18
-
Then I would need you to give me some details on what are you trying to accomplish. You want to have several container on a host with each container having a unique ip assigned statically by you or the dhcp on your network ? Jan 17, 2018 at 21:42
-
Yes, some containers on host server, on which I can install something for local using. I have dhcp-server, but will be better to set static ip addresses.– StefanJan 17, 2018 at 21:49
-
@Stefan I've edited the answer with something I think will suit your needs. Jan 17, 2018 at 22:14
-
When trying to use this command ip addr del <IP>/24 dev <interface_name> get the next error: "Error: either "local" is duplicate, or "ens32" is a garbage."– StefanJan 18, 2018 at 8:13