4

docker 设置固定IP

 3 years ago
source link: http://abcdxyzk.github.io/blog/2020/11/07/docker-ip/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

1 设置固定IP

使用默认的网络是不支持指派固定IP的

# 创建自定义网络
docker network create --subnet=192.168.3.0/24 --gateway=192.168.3.1 nett
docker network ls

#
docker run -i -t --net nett --ip 192.168.3.2 49f7960eb7e4 /bin/bash

2 修改bridge

brctl addbr br1
brctl show

vim /etc/sysconfig/docker
ifconfig br1 100.64.0.1 netmask 255.255.255.0

vim /etc/sysconfig/docker-network
DOCKER_NETWORK_OPTIONS="-b=br1"

service docker restart

或者配置docker

3 pipework配置docker网络

pipework-master.zip

git clone https://github.com/jpetazzo/pipework.git
sudo cp pipework/pipework /usr/local/bin/

docker run -itd --name d1 --net=none centos2 /bin/bash
pipework br1 d1 100.64.0.100/[email protected]
docker exec -it d1 /bin/bash

4 修改本机为bridge, docker分配同本机网段

vim /etc/sysconfig/network-scripts/ifcfg-enp0s3

增加 BRIDGE="br0"

vim /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE="br0"
ONBOOT="yes"
TYPE="Bridge"
BOOTPROTO=dhcp

service network restart

echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/enp0s3/proxy_arp

docker run -itd --name d2 --net=none centos2 /bin/bash
pipework br0 d2 192.168.43.189/[email protected]
brctl show

docker exec -it d2 /bin/bash

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK