如何正确指定停泊港集装箱的IP [英] how to properly specify an IP for a docker container
问题描述
我试图以下列方式明确指定我的docker容器的IP地址:
I'm trying to explicitly specify an IP address for my docker container in the following way:
sudo docker run -it -p 172.17.0.2:10000:10000 -p 9000:9000 -p 9090:9090 -v /home/eugene/dev/shared:/opt/shared -d eugene/dev_img_1.3
我收到以下错误:
Error response from daemon: Cannot start container b2242e5da6e1b701ba4880f25fa8d465d5f008787b49898ad9e46eb26e417e48: port has already been allocated
我真的做不关心端口10000.我的目标是拥有我选择的特定容器IP,以及端口9000和9090暴露给主机。
I really do not care about port 10000. My goal is to have a specific container IP of my choosing, as well as to have ports 9000 and 9090 exposed to the host.
我有看了一些其他问题,但没有看到清楚的语法来做到这一点。
I have looked at some other questions, but did not see a clear syntax to do this
推荐答案
-p
参数用于将端口从容器转发到主机,而不是分配IP。
The -p
argument is used to forward ports from the container to the host, not for assigning IPs.
没有简单的方法来屁股点一个固定的IP到Docker容器,我强烈建议你不要尝试。而是重新构建您的系统,使其不依赖于固定IP。如果这是不可能的,我想你可以通过使用LXC执行驱动程序和各种标志来选择一个IP,但是我强烈推荐这样做。
There is no easy way to assign a fixed IP to a Docker container and I would strongly advise you not to try. Instead re-architect your system so that it isn't dependent on a fixed IP. If this really isn't possible, I think you can choose an IP by using the LXC execution driver and various flags, but I would strongly recommend against this.
这篇关于如何正确指定停泊港集装箱的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!