MCPcopy
hub / github.com/docker/compose / prepareContainerMACAddress

Method prepareContainerMACAddress

pkg/compose/create.go:352–372  ·  pkg/compose/create.go::composeService.prepareContainerMACAddress

prepareContainerMACAddress handles the service-level mac_address field and the newer mac_address field added to service network config. This newer field is only compatible with the Engine API v1.44 (and onwards), and this API version also deprecates the container-wide mac_address field. Thus, this m

(service types.ServiceConfig, mainNw *types.ServiceNetworkConfig, nwName string)

Source from the content-addressed store, hash-verified

350//
351// It returns the container-wide MAC address, but this value will be kept empty for newer API versions.
352func (s *composeService) prepareContainerMACAddress(service types.ServiceConfig, mainNw *types.ServiceNetworkConfig, nwName string) error {
353 // Engine API 1.44 added support for endpoint-specific MAC address and now returns a warning when a MAC address is
354 // set in container.Config. Thus, we have to jump through a number of hoops:
355 //
356 // 1. Top-level mac_address and main endpoint's MAC address should be the same ;
357 // 2. If supported by the API, top-level mac_address should be migrated to the main endpoint and container.Config
358 // should be kept empty ;
359 // 3. Otherwise, the endpoint mac_address should be set in container.Config and no other endpoint-specific
360 // mac_address can be specified. If that's the case, use top-level mac_address ;
361 //
362 // After that, if an endpoint mac_address is set, it's either user-defined or migrated by the code below, so
363 // there's no need to check for API version in defaultNetworkSettings.
364 macAddress := service.MacAddress
365 if macAddress != "" && mainNw != nil && mainNw.MacAddress != "" && mainNw.MacAddress != macAddress {
366 return fmt.Errorf("the service-level mac_address should have the same value as network %s", nwName)
367 }
368 if mainNw != nil && mainNw.MacAddress == "" {
369 mainNw.MacAddress = macAddress
370 }
371 return nil
372}
373
374func getAliases(project *types.Project, service types.ServiceConfig, serviceIndex int, cfg *types.ServiceNetworkConfig, useNetworkAliases bool) []string {
375 aliases := []string{getContainerName(project.Name, service, serviceIndex)}

Callers 1

getCreateConfigsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected