Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

随机端口让 docker 自动分配 #42

wei opened this Issue Mar 2, 2019 · 2 comments


None yet
2 participants
Copy link

wei commented Mar 2, 2019

--expose             |   Expose a port or a range of ports
--publish-all , -P   |   Publish all exposed ports to random ports

可以直接让 docker 分配端口

docker run -d --name container --expose 1588 --publish-all

p.s. 话说现在这个 randport 能从容器内查服务器外部端口打开情况吗?


Lines 158 to 168 in 92fd313

def randPort():
rand_port = random.randint(1, 65536)
if (6000 <= rand_port <= 7000) or (rand_port == 22):
subprocess.check_output("lsof -i:%s" % (rand_port), shell=True)
except subprocess.CalledProcessError:
return rand_port

@wei wei added the enhancement label Mar 2, 2019


This comment has been minimized.

Copy link

import-yuefeng commented Mar 2, 2019

似乎是一个设计失误, 在封装好的docker 版本的inspire无法判断宿主机的端口是否被使用.
(不过之前似乎很少出现这个问题, 没人提issue🤔


  1. 存redis吧? 根据每次的create/rm API来维护host的端口占用情况.
  2. 或者就是上面说的docker的指令即可, 调用的是宿主机的docker, 应该是可行的.

This comment has been minimized.

Copy link
Member Author

wei commented Mar 2, 2019

嗯嗯 还是 2 比较优美 本来就是 docker 专门为这种 use case 设计的。
1 的话宿主机上运行别的东西就有冲突了 😄

@wei wei changed the title 随机端口考虑使用 docker run 自动分配 随机端口让 docker 自动分配 Mar 2, 2019

@wei wei closed this in #44 Mar 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.