moby: --network-alias option missing on docker service create (as well as corresponding options on docker service update)

docker/docker#23542 added support for network aliasing of services. Comment 2 in docker/libnetwork#1263 shows this feature in action, by providing the --network-alias option to docker service create. However, for all clients I checked, this just returns the error unknown flag: --network-alias. This also applies for docker service update (flags should probably be --network-alias-add and --network-alias-rm here).

Clients tested were:

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 22
  • Comments: 32 (7 by maintainers)

Commits related to this issue

Most upvoted comments

1.13 release is coming. Any news ?

Hi, I agree this suggestion is going to be a good improvement. It could be very useful to duplicate the same stack of services in different overlay networks. As the service name can’t be duplicated this is not possible at the moment until we are able to force the name in network.

As I knew about the --network-alias argument I was going to use this feature for blue-green deployments. I felt disappointed when I realised this feature is gone.

I’ll keep an eye on this milestone. Thanks!!

I just got here because @thaJeztah pointed me to this issue from https://github.com/docker/docker/issues/30419. I need network-aliases for a service which runs with mode:global. But the network-alias must support the usage of templates to give each running container a unique network-alias.

If this is already available in API but not CLI, can I use {{.Task.Slot}} as part of network alias? Some think like:

–network-alias zookeeper-{{.Task.Slot}}

But through API directly?

This issue is similar to the closed issue #26247, since 1.13 introduced template support for hostname, mount and env while creating services(#28486), I think it’s reasonable to add template support for this network-alias feature too. This feature would ease Cluster HA setup(Spark/Elasticsearch/…), worker/slave nodes need the master node hostname/IP before setup.

Yeah I needed that namespacing stuffs also. Pointed out in https://github.com/docker/docker/issues/25369. Still not sure what the command line argument should look like in terms of consistency to the existing ones.

@hvpareja note my comment right after: (there are different containers providing the same service on different networks)

Ok, so I should have written “overlay networks” there, but my point was if you have a testing and a staging environment which both have a database, they can’t both be called “database”, whereas with links that was possible. So now testing and staging cannot use the same configuration.

In other word, adding the --network-alias switch is a good idea.

I tried to do this as well using a compose file for docker stack deploy but no luck:

service:
  db:
    image: mariadb:10.2
    networks:
      nodelocal:
        aliases:
          - db_nodelocal
      swarm:
    deploy:
      mode: global
      endpoint_mode: dnsrr
networks:
  swarm:
    driver: overlay
  nodelocal:
    external: true

Although everything starts up fine and it connects to both networks, but the only alias that appears on the nodelocal network via docker inspect is the container id.

Would really love this since I normally use <name>.{{ .Task.Slot }} and would like to use them by domain name. Currenlt I use endpoint spec with dnsrr, and do a reverse lookup for the IP addreses, which is really not cool.

Fully agree, net-alias should support templates . 👍 Any news about a delivery date for this feature ?

My use case is, that I have a haproxy reverse proxy and I need to route internal network traffic through this haproxy to different microservices. To be able to this I need --network-alias or otherwise I have to touch all other containers and modify hosts which is not always possible. Another possibility would be to deploy a DNS service, which I would like to avoid.

@cirocosta the aliases are network scoped; I believe the suggestion by @Stehsegler in his comment https://github.com/docker/docker/issues/24787#issuecomment-233853394 makes sense. That is, you must be able to define which network a given alias applies to.

However, declaring network aliases along with --network might be a somewhat tricky approach if you want to add or remove aliases later on. It could, be that allowing something like --network-alias net1:alias2 net1:alias2 could be a way to go. In other words, keep declaration of aliases on its own.

@mavenugo How do we add the network alias to a service via the API? I’ve looked through the docker-py docs and was unable to find a way to do this.