在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jpetazzo/pipework开源软件地址(OpenSource Url):https://github.com/jpetazzo/pipework开源编程语言(OpenSource Language):Shell 99.6%开源软件介绍(OpenSource Introduction):PipeworkSoftware-Defined Networking for Linux Containers Pipework lets you connect together containers in arbitrarily complex scenarios.
Pipework uses cgroups and namespace and works with "plain" LXC containers
(created with Table of Contents generated with DocToc
Things to notevCenter / vSphere / ESX / ESXiIf you use vCenter / VSphere / ESX / ESXi, set or ask your administrator to set Network Security Policies of the vSwitch as below:
After starting the guest OS and creating a bridge, you might also need to
fine-tune the
VirtualboxIf you use VirtualBox, you will have to update your VM network settings.
Open the settings panel for the VM, go the the "Network" tab, pull down the
"Advanced" settings. Here, the "Adapter Type" should be If you don't do that, bridged containers won't work, because the virtual
NIC will filter out all packets with a different MAC address. If you are
running VirtualBox in headless mode, the command line equivalent of the above
is config.vm.provider "virtualbox" do |v|
v.customize ['modifyvm', :id, '--nictype1', 'Am79C973']
v.customize ['modifyvm', :id, '--nicpromisc1', 'allow-all']
end Note: it looks like some operating systems (e.g. CentOS 7) do not support
DockerBefore using Pipework, please ask on the docker-user mailing list if there is a "native" way to achieve what you want to do without Pipework. In the long run, Docker will allow complex scenarios, and Pipework should become obsolete. If there is really no other way to plumb your containers together with the current version of Docker, then okay, let's see how we can help you! The following examples show what Pipework can do for you and your containers. LAMP stack with a private network between the MySQL and Apache containersLet's create two containers, running the web tier and the database tier:
Now, bring superpowers to the web tier:
This will:
Now (drum roll), let's do this:
This will:
Now, both containers can ping each other on the 192.168.1.0/24 subnet. Docker integrationPipework can resolve Docker containers names. If the container ID that
you gave to Pipework cannot be found, Pipework will try to resolve it
with
Peeking inside the private networkWant to connect to those containers using their private addresses? Easy:
Voilà! Setting container internal interfaceBy default pipework creates a new interface
Note:: for InfiniBand IPoIB interfaces, the default interface name is Setting host interface nameBy default pipework will create a host-side interface with a fixed prefix but random suffix. If you would like to specify this interface name use the
Using a different netmaskThe IP addresses given to I.e.:
Don't forget that all containers should use the same subnet size; pipework is not clever enough to use your specified subnet size for the first container, and retain it to use it for the other containers. Setting a default gatewayIf you want outbound traffic (i.e. when the containers connects to the outside world) to go through the interface managed by Pipework, you need to change the default route of the container. This can be useful in some usecases, like traffic shaping, or if you want the container to use a specific outbound IP address. This can be automated by Pipework, by adding the gateway address after the IP address and subnet mask:
Connect a container to a local physical interfaceLet's pretend that you want to run two Hipache instances, listening on real interfaces eth2 and eth3, using specific (public) IP addresses. Easy!
Note that this will use
This is useful for assigning SR-IOV VFs to containers, but be aware of added latency when using the NIC to switch packets between containers on the same host. Use MAC address to specify physical interfaceIn case you want to connect a local physical interface with a specific name inside the container, it will also rename the physical one, this behaviour is not idempotent:
We can use the interface MAC address to identify the interface the same way any time (udev networking rules use a similar method for interfaces persistent naming):
Let the Docker host communicate over macvlan interfacesIf you use macvlan interfaces as shown in the previous paragraph, you will notice that the host will not be able to reach the containers over their macvlan interfaces. This is because traffic going in and out of macvlan interfaces is segregated from the "root" interface. If you want to enable that kind of communication, no problem: just create a macvlan interface in your host, and move the IP address from the "normal" interface to the macvlan interface. For instance, on a machine where
Then, you would start a container and assign it a macvlan interface the usual way:
Wait for the network to be readySometimes, you want the extra network interface to be up and running before
starting your service. A dirty (and unreliable) solution would be to add
a There is a better option: add the If you need to wait on an interface other than eth1, pass the -i flag like this:
Add the interface without an IP addressIf for some reason you want to set the IP address from within the
container, you can use
Add a dummy interfaceIf for some reason you want a dummy interface inside the container, you can add it like any other interface. Just set the host interface to the keyword dummy. All other options - IP, CIDR, gateway - function as normal.
Of course, a gateway does not mean much in the context of a dummy interface, but there it is. DHCPYou can use DHCP to obtain the IP address of the new interface. Just specify the name of the DHCP client that you want to use instead on an IP address; for instance:
You can specify the following DHCP clients:
The first three are "normal" DHCP clients. They have to be installed
on your host for this option to work. The last one works
differently: it will run a DHCP client in a Docker container
sharing its network namespace with your container. This allows
to use DHCP configuration without worrying about installing the
right DHCP client on your host. It will use the Docker The value of $CONTAINERID will be provided to the DHCP client to use as the hostname in the DHCP request. Depending on the configuration of your network's DHCP server, this may enable other machines on the network to access the container using the $CONTAINERID as a hostname; therefore, specifying $CONTAINERID as a container name rather than a container id may be more appropriate in this use-case. You need three things for this to work correctly:
The last item might be particularly relevant if you are trying to bridge your containers with a WPA-protected WiFi network. I'm not 100% sure about this, but I think that the WiFi access point will drop frames originating from unknown MAC addresses; meaning that you have to go through extra hoops if you want it to work properly. It works fine on plain old wired Ethernet, though. Lease RenewalAll of the DHCP options - udhcpc, dhcp, dhclient, dhcpcd - exit or are killed by pipework when they are done assigning a lease. This is to prevent zombie processes from existing after a container exits, but the dhcp client still exists. However, if the container is long-running - longer than the life of the lease - then the lease will expire, no dhcp client renews the lease, and the container is stuck without a valid IP address. To resolve this problem, you can cause the dhcp client to remain alive. The method depends on the dhcp client you use.
Note: If you use this option you will be responsible for finding and killing those dhcp client processes in the future. pipework is a one-time script; it is not intended to manage long-running processes for you. In order to find the processes, you can look for pidfiles in the following locations:
DHCP OptionsYou can specify extra DHCP options to be passed to the DHCP client by adding them with a colon. For instance:
This will tell Pipework to setup the interface using the DHCP client
of the Docker Without this flag, a new container is started, in which the DHCP client is executed. The DHCP client obtains a lease, then goes to the background. When it goes to the background, the PID 1 in this container exits, causing the whole container to be terminated. As a result, the "pipeworked" container has its IP address, but the DHCP client has gone. On the up side, you don't have any cleanup to do; on the other, the DHCP lease will not be renewed, which could be problematic if you have short leases and the server and other clients don't validate their leases before using them. With this flag, a new container is started, it runs the DHCP client just like before; but when it obtains the lease, it remains in the foreground. As a result, the lease will be properly renewed. However, when you terminate the "pipeworked" container, you should also take care of removing the container that runs the DHCP client. This can be seen as an advantage if you want to reuse this network stack even if the initial container is terminated. Specify a custom MAC addressIf you need to specify the MAC address to be used (either by the
This can be useful if your network environment requires whitelisting your hardware addresses (some hosting providers do that), or if you want to obtain a specific address from your DHCP server. Also, some projects like Orchestrator rely on static MAC-IPv6 bindings for DHCPv6:
Note: if you generate your own MAC addresses, try remember those two simple rules:
In other words, if your MAC address is If you want a consistent MAC address across container restarts, but don't want to have to keep track of the messy MAC addresses, ask pipework to generate an address for you based on a specified string, e.g. the hostname. This guarantees a consistent MAC address:
pipework will take some_string and hash it using MD5. It will then take the first 40 bits of the MD5 hash, add those to the locally administered prefix of 0x02, and create a unique MAC address. For example, if your unique string is "myhost.foo.com", then the MAC address will always be This is particularly useful in the case of DHCP, where you might want the container to stop and start, but always get the same address. Most DHCP servers will keep giving you a consistent IP address if the MAC address is consistent. Note: Setting the MAC address of an IPoIB interface is not supported. Virtual LAN (VLAN)If you want to attach the container to a specific VLAN, the VLAN ID can be
specified using the Note: VLAN attachment is currently only supported for containers to be attached to either an Open vSwitch bridge or a physical interface. Linux bridges are currently not supported. The following will attach container zerorpcworker to the Open vSwitch bridge ovs0 and attach the container to VLAN ID 10.
Control RoutesIf you want to add/delete/replace routes in the container, you can run any iproute2 route command via pipework. All you have to do is set the interface to be Here are some examples.
Everything after the container ID (or name) will be run as an argument to Control RulesIf you want to add/delete/replace IP rules in the container, you can do the same thing with Specify the interface to be Here are some examples, to specify a route table:
Note that for these rules to work you first need to execute the following in your container: echo "1 admin" >> /etc/iproute2/rt_tables You can read more on using route tables, specifically to setup multiple NICs with different default gateways, here: https://kindlund.wordpress.com/2007/11/19/configuring-multiple-default-routes-in-linux/
Control |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论