Skip to content

Add service networks driver options keys passed to custom libnetwork drivers #8339

@jfellus

Description

@jfellus

docker network connect exposes a --driver-opt commandline option to pass per-container options to the (eventually custom) libnetwork driver.

While docker network create --opt <key>=<value> is perfectly mapped the docker-compose equivalent

networks:
    mynet:
        driver: some-custom-libnetwork-driver-plugin
        driver_opts:
             some.key: value

I can't find the compose equivalent for per-container options, something like :

services:
   myservice:
      ...
      networks:
          mynet:
              driver_opts:
                  some.container.specific.key: "value_for_myservice"

Implications of this limitation

In the libnetwork remote driver spec when a container joins a network, the driver is responsible for allocating an IP address during the CreateEndpoint call. It is called with the (randomly generated) NetworkID, the EndpointID and the per-container driver opts and must return an IP address among other things. At this stage, you can't get anything related to the said container's config, so accessing hostname, container_name, or any container-related conf that may be useful for the network driver to make its decision about the container's IP (e.g. via a DHCP request or whatever) is impossible. You're left with a meaningless EndpointID you can't map to the container's identity

In a Docker CLI context, you would easily overcome the problem by passing those information via per-container driver_opts flags : docker network connect --driver-opt.

The absence of such key in the compose file spec prevents per-container custom network config in the docker-compose.yml file, which is sad.

Proposal

Add a driver_opts key under the services > * > networks > * > dict and pass them to Docker

I'm open to submitting a PR about that, but let me know if someone else is interested in this feat please.

Activity

stale

stale commented on Apr 16, 2022

@stale

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale

stale commented on Apr 27, 2022

@stale

This issue has been automatically closed because it had not recent activity during the stale period.

added a commit that references this issue on Nov 29, 2022
added a commit that references this issue on Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jfellus

      Issue actions

        Add service networks driver options keys passed to custom libnetwork drivers · Issue #8339 · docker/compose