动态/可变端口映射

时间:2018-08-29 09:54:15

标签: docker-compose

我们有几个运行Apache2服务器的Docker映像,并使用prometheus从它们中抓取数据:

Docker-compose文件(最小):

version: "3.3"

services:
  noteable:
    image: naas/noteable
    ports:
      - 9118:9117

  proxy:
    image: /naas/noteable_proxy
    ports:
      - 80:8080
      - 9117:9117

以这种格式,这两种服务都在端口9117上公开了普罗米修斯数据,然后将其映射到主机上的不同端口。

如果我尝试扩展noteable服务,则会发生端口冲突:

[naas@naas-dev ~]$ docker-compose up --no-recreate --scale noteable=2
Starting naas_proxy_1 ... 
WARNING: The "noteable" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.
Starting naas_noteable_1 ... done
Creating naas_noteable_2 ... error

ERROR: for naas_noteable_2  Cannot start service noteable: driver failed programming external connectivity on endpoint naas_noteable_2 (47ff958b454ce75887ea4a2b8f1b42f8618dc04f3911fa9190fb27129443728a): Bind for 0.0.0.0:9118 failed: port is already allocated

ERROR: for noteable  Cannot start service noteable: driver failed programming external connectivity on endpoint naas_noteable_2 (47ff958b454ce75887ea4a2b8f1b42f8618dc04f3911fa9190fb27129443728a): Bind for 0.0.0.0:9118 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.

(确实很明显)

问题:是否有一些聪明的方法来做9117+:9117(例如,“映射到9117,或此后的下一个可用端口”)?

0 个答案:

没有答案
相关问题