Hello,
I'm trying to create a service publishing a port in host mode with the Python SDK, but i don't see option to do so :(
It is possible via docker command line (https://docs.docker.com/engine/reference/commandline/service_create/#options) :
docker service create -p mode=host,published=80,target=80 --name test httpd
It is also possible via docker-compose:
services:
test:
image: httpd
ports:
- mode: host
target: 80
published: 80
deploy:
mode: replicated
replicas: 1
Is there a way to achieve the same result via python SDK ?
Thanks !
Hi @greenmaid. You should use https://docker-py.readthedocs.io/en/stable/api.html#docker.types.EndpointSpec. Regards.
Hello @feliperuhland , thanks for your reply !
In fact, EndpointSpec only support "vip" and "dnsrr" modes. I'm looking for the "host" mode. IMHO it is even not the same kind of 'mode' we are speaking about.... If i understand well, "vip"/"dnsrr" mode refers to internal swarm load-balancing mode, the "host" mode i'm looking for refers to external port publishing...
A more precise link from docker documentation: https://docs.docker.com/engine/reference/commandline/service_create/#publish-service-ports-externally-to-the-swarm--p-publish
Regards
@greenmaid You're right - we don't have support for it currently, unfortunately. Thanks for bringing it to our attention.
It looks like there still isn't a way to create a service with published ports using mode=host i.e., without the routing mesh.
EDIT: The Docker REST API does support this in /services/create/ (EndpointSpec->Ports->PublishMode)
@jgeryk I believe you are mistaken.
Exposed ports that this service is accessible on from the outside, in the form of [...]
{ published_port: <port_config_tuple> }. Port config tuple format is(target_port [, protocol [, publish_mode]]).
I don't know how I missed that. Thank you!
Most helpful comment
@jgeryk I believe you are mistaken.