下面是我试图用mininet(containernet)创建的拓扑结构,其中有3个容器,中间有第2层交换机。我想访问这些容器(例如。Kali Linux容器)在浏览器上的本地主机上。我试着像文档中所说的那样暴露端口,但我仍然无法在浏览器上访问它。注意-我可以访问容器(如kali linux容器),如果我不使用本地主机上的containernet。参考第三台主机使用以下docker容器- https://hub.docker.com/r/lukaszlach/kali-desktop
#!/usr/bin/python
from mininet.net import Containernet
from mininet.node import Controller
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import info, setLogLevel
#VNC_DEFAULT = 5900
#WEB_DEFAULT = 6080
setLogLevel('info')
net = Containernet(controller=Controller)
info('*** Adding controllern')
net.addController('c0' )
info('*** Adding docker containersn')
d1 = net.addDocker('d1', ip='10.0.2.16', dimage="virtualmogli_v1_service1", ports=[5000], port_bindings={5000:5000},publish_all_ports=True)
d2 = net.addDocker('d2', ip='10.0.2.15', dimage="virtualmogli_v1_service2", ports=[5001], port_bindings={5001:5001},publish_all_ports=True)
d3 = net.addDocker('d3', ip='10.0.2.17', dimage="virtualmogli_v1_kalicontainer", ports=[5900, 6080], port_bindings={5900: 5900, 6080: 6080}, publish_all_ports=True,)
info('*** Adding switchesn')
s1 = net.addSwitch('s1')
#s2 = net.addSwitch('s2')
info('*** Creating linksn')
net.addLink(d1, s1, cls=TCLink, delay='100ms', bw=1)
#net.addLink(s1, s2, cls=TCLink, delay='100ms', bw=1)
net.addLink(s1, d2, cls=TCLink, delay='100ms', bw=1)
net.addLink(s1, d3, cls=TCLink, delay='100ms', bw=1)
info('*** Starting networkn')
net.start()
info('*** Testing connectivityn')
net.ping([d1, d2, d3])
info('*** Running CLIn')
CLI(net)
info('*** Stopping network')
net.stop()
我们需要将dcmd="/init"
添加到我们的容器网络拓扑中,而不是我们的基类。
对于上面的问题,下面的代码将工作-d2 = net.addDocker('d2', ip='10.0.2.15', dimage="lukaszlach/kali-desktop:xfce-top10",ports=[5900,6080],dcmd="/init , port_bindings={5900:5900,6080:6080},publish_all_ports= True, environment={"USER": "kali", "PASSWORD": "kali" , "ROOT_PASSWORD": "root"})