Use the appropriate Docker network API method based on the specific behavior you need. NetworkList and NetworkInspect have different matching behaviors that can lead to unexpected results if used incorrectly.

Key distinctions:

Example of proper network resolution:

// Use NetworkList for exact name matching
networks, err := s.apiClient().NetworkList(ctx, moby.NetworkListOptions{
    Filters: filters.NewArgs(filters.Arg("name", networkName)),
})
if err != nil {
    return err
}

// Filter for exact match since NetworkList can return partial matches
networks = utils.Filter(networks, func(net moby.NetworkResource) bool {
    return net.Name == networkName
})

// Check for proper labels to ensure it's the expected network
for _, net := range networks {
    if net.Labels[api.ProjectLabel] == expectedProjectLabel &&
       net.Labels[api.NetworkLabel] == expectedNetworkLabel {
        return nil
    }
}

This approach prevents issues like matching a network named db to a network with ID db9086999caf and ensures you’re working with the intended network resource.