Home > other >  How to assign the container a fixed IP
How to assign the container a fixed IP

Time:10-03

The method is as follows:

1. The host machine with the bridge (the following configuration in centos, for example, ubuntu or other users of the system can be online to check how to configure the bridge)
Edit the following two files
The/etc/sysconfig/network - scripts/ifcfg - eth1
 
DEVICE='eth1'
ONBOOT=yes
BRIDGE=br1

The/etc/sysconfig/network - scripts/ifcfg - br1
 
DEVICE='br1'
TYPE=Bridge,
BOOTPROTO=static
ONBOOT=yes
IPADDR='X.X.X.X'
NETMASK='X.X.X.X'
GATEWAY='X.X.X.X'

And then restart the effective network card
 
The/etc/init. D/network restart

2. Use pipework management container IP
Pipework https://github.com/jpetazzo/pipework
When using pipework to each container allocation IP, to quote the following wrong
The Object "nets" is unknown, the try "IP help".

The cause and solution:
Centos6.5 kernel has supported network namespace, but install iproute version is too low, not support IP nets command,
Upgrade iproute to iproute-2.6.32-130.el6ost.net ns. 2. X86_64

The method is as follows:
 
# yum install http://rdo.fedorapeople.org/rdo-release.rpm
# yum install iproute


3. Use example
 
TESTID=$(docker run - d bangli/centos - SSHD)
./pipework br1 $TESTID 10.10.0.10/24 @10.0.0.1

10.10.0.10/24 is specify IP and subnet mask for the container
10.0.0.1 as the default gateway
These need to be specified according to actual condition,

CodePudding user response:

Haven't been configuration fixed IP, bridge is tried

CodePudding user response:

  • Related