code: func (daemon *Daemon) registerLinks(container *container.Container, hostConfig *containertypes.HostConfig) error {
  	if hostConfig == nil || hostConfig.NetworkMode.IsUserDefined() {
  		return nil
  	}
  
  	for _, l := range hostConfig.Links {
  		name, alias, err := opts.ParseLink(l)
  		if err != nil {
  			return err
  		}
  		child, err := daemon.GetContainer(name)
  		if err != nil {
  			return errors.Wrapf(err, "could not get container for %s", name)
  		}
  		for child.HostConfig.NetworkMode.IsContainer() {
  			parts := strings.SplitN(string(child.HostConfig.NetworkMode), ":", 2)
  			child, err = daemon.GetContainer(parts[1])
  			if err != nil {
  				return errors.Wrapf(err, "Could not get container for %s", parts[1])
  			}
  		}
  		if child.HostConfig.NetworkMode.IsHost() {
  			return runconfig.ErrConflictHostNetworkAndLinks
  		}
  		if err := daemon.registerLink(container, child, alias); err != nil {
  			return err
  		}
  	}
  
  	// After we load all the links into the daemon
  	// set them to nil on the hostconfig
  	_, err := container.WriteHostConfig()
  	return err
  }
docs: // registerLinks writes the links to a file.