简体   繁体   English

如何将多个接口添加到Docker容器并手动设置IP地址?

[英]How to add multiple interfaces to docker container and set ip addresses manually?

I can set IP address manully by using this command: 我可以使用以下命令手动设置IP地址:

docker run --lxc-conf="lxc.network.ipv4 = 172.17.0.12/16" -a stdin -a stdout -a stderr -i -t dockerimage /bin/bash

How to add multiple interfaces to docker container and set IP addresses manually? 如何在Docker容器中添加多个接口并手动设置IP地址?

I solved this by using these commands: 我通过使用以下命令解决了这个问题:

dockerContainer=$(docker run --lxc-conf="lxc.network.ipv4 = 172.17.0.21/16" -d dockerimage)
sudo pipework docker0 -i eth1 $dockerContainer 172.17.0.22/24

'docker run' command creates eth0 and I set eth0 manually by using lxc.network.ipv4 configuration. 'docker run'命令创建eth0,我使用lxc.network.ipv4配置手动设置eth0。 And then I add interface eth1 by using pipework. 然后我通过使用管道添加接口eth1。

I'm glad you solved this, but it's worth pointing out that this is very much against the philosophy of Docker. 我很高兴您解决了这个问题,但是值得指出的是,这与Docker的理念非常抵触。 You should try to architect your application so that it can deal with changing IPs. 您应该尝试设计您的应用程序,以便它可以处理不断变化的IP。 Containers are supposed to be dynamic and transient. 容器应该是动态的和瞬态的。 This does mean that there is a lot of on-going work in terms service-discovery and orchestration. 这确实意味着在服务发现和编排方面还有很多正在进行的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM