多语言展示
当前在线:724今日阅读:39今日分享:10

docker创建macvlan网卡方法

docker有四种网络模式,分别为host模式、 container模式  、none模式、bridge模式等。macvlan属于bridge网络模式
工具/原料
1

docker

2

centos7.4

方法/步骤
1

做本实验之前需要先安装好dokcer并已经启动docker服务

2

通过ifconfig命令确定物理网卡的名称为ens32,以及网段netmask 255.255.255.0,应该为192.168.137.0/24

3

route -n命令获取到网关为192.168.137.2

4

使用下面命令创建网卡,名称为macnetdocker network create -d macvlan --subnet 192.168.137.0/24 --gateway 192.168.137.2 -o parent=ens32 -o macvlan_mode=bridge macnet

5

docker network ls命令查看网卡名称,名称为macnet的网卡已经添加成功

6

通过下面命令加上新增的网卡名称,就能够获取到网卡明细了docker network inspect macnet

7

下面步骤是获取dokcer image,并测试新建的网卡macnet查找mysql相关的镜像docker search mysql

9

使用下面命令创建一个ip地址为192.168.137.3的容器,使用网卡macnet docker run --privileged -ti --net macnet --ip 192.168.137.3 -d --name jdk1 centos7:jdk1.8_F /usr/sbin/init

10

使用下面命令进入容器并测试网络docker exec -it jdk1 /bin/bash

推荐信息