compose/pkg
Milas Bowman 0f747419b6 networks: prevent issues due to duplicate names
Within the Docker API/engine, networks have unique IDs, and the
name is a friendly label/alias, which notably does NOT have any
guarantees around uniqueness (see moby/moby#18864 [^1]).

During day-to-day interactive/CLI Compose usage, this is rarely
an issue, as Compose itself isn't creating networks concurrently
across goroutines. However, if multiple Compose instances are
executed simultaneously (e.g. as part of a test suite that runs
in parallel), this can easily occur.

When it does happen, it's very confusing for users and resolving
it via the `docker` CLI is not straightforward either [^2].

There's two primary changes here:
 * Pass `CheckDuplicates: true` to the Docker API when creating
   networks to reduce the likelihood of Compose creating duplicates
   in the first place
 * On `down`, list networks using a name filter and then remove
   them all by ID, as the Docker API will return an error if the
   name alias is used and maps to more than one network

Hopefully, this provides a better UX, since the issue should be
less likely to occur, and if it does, it can now be resolved via
standard Compose workflow commands.

[^1]: https://github.com/moby/moby/issues/18864
[^2]: https://stackoverflow.com/questions/63776518/error-2-matches-found-based-on-name-network-nameofservice-default-is-ambiguo

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
2022-06-22 12:27:30 -04:00
..
api project name MUST be lowercase 2022-04-13 09:49:01 +02:00
compose networks: prevent issues due to duplicate names 2022-06-22 12:27:30 -04:00
e2e e2e: improve test output on failures 2022-06-16 17:05:43 -04:00
mocks mocks: create mocks for compose api.Service 2022-06-07 17:09:06 -05:00
progress fix: prevent flickering prompt when pulling same image from N services 2022-05-18 08:58:06 +02:00
prompt move compose-cli code into docker/compose/v2 2021-08-31 19:09:19 +02:00
utils Add function to convert strings to bool 2022-03-04 16:42:37 +01:00