Search code examples
docker-swarmvsftpddocker-swarm-mode

Expose a range of ports in docker service


Is there any way to expose a range of ports in the creation of a swarm service ( for instance: -p 1024-2000:1024-2000)? I know that it's possible for a container, but is it also possible for a Swarm Service? If yes, I can't find how to do that in the documentation.

I need this functionality for exposing a service that contains vsftpd.


Solution

  • After posting the issue https://github.com/docker/docker/issues/30560, I had the response that this functionality was available in the version 1.13.

    For the others that can't upgrade to this version, I have written a script bash that will do a loop to bind all the ports:

      expose_range(){
              p="";
              for i in `seq $1 $2`;
              do
                if [[ $3 != '--publish-rm' ]]; then
                  p="$p $3 $i:$i"
                else
                  p="$p $3 $i"
                fi
              done
              echo $p
      }
      command="docker service create --name vsftpd -p 2021:21 `expose_range ${vsftpd_port_min} ${vsftpd_port_max} '-p'` panubo/vsftpd"
      eval $command