简体   繁体   中英

docker swarm published port range

When publishing ports with docker run , we can have docker dynamically choose a host port from within a specified range, for example:

~ $ docker run -d -p 30005-30010:80 alpine tail -f /dev/null
263d3cfa4ba591cb9a1adb5087058aa716c534f33a498cc5457c0c2152b41808
~ $ docker port 263
80/tcp -> 0.0.0.0:30005

Here, docker has chosen a free port in the range 30005-30010 on the host to map to the container's port 80. It does not seem possible to do this with docker swarm services, either using the cli or compose files. eg

~ $ docker service create -p 30005-30010:80 alpine tail -f /dev/null
invalid argument "30005-30010:80" for p: invalid hostport binding (30005-30010) for port (80)

Is this a limitation of swarm mode, or am I missing something?

The port range doesn't seem to be supported in swarm with docker service create ... .

It is also not supported in stack files. The same error shows when you do docker stack deploy ... with a host port range.

The random port however is supported:

docker service create -p :80 alpine tail -f /dev/null

You can request this feature by inserting an issue in https://github.com/docker/swarm/issues

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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