github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/daemon/container_operations_windows.go (about)

     1  package daemon // import "github.com/docker/docker/daemon"
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"os"
     7  
     8  	"github.com/docker/docker/container"
     9  	"github.com/docker/docker/pkg/system"
    10  	"github.com/docker/libnetwork"
    11  	"github.com/pkg/errors"
    12  	"github.com/sirupsen/logrus"
    13  )
    14  
    15  func (daemon *Daemon) setupLinkedContainers(container *container.Container) ([]string, error) {
    16  	return nil, nil
    17  }
    18  
    19  func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
    20  	if len(c.ConfigReferences) == 0 {
    21  		return nil
    22  	}
    23  
    24  	localPath := c.ConfigsDirPath()
    25  	logrus.Debugf("configs: setting up config dir: %s", localPath)
    26  
    27  	// create local config root
    28  	if err := system.MkdirAllWithACL(localPath, 0, system.SddlAdministratorsLocalSystem); err != nil {
    29  		return errors.Wrap(err, "error creating config dir")
    30  	}
    31  
    32  	defer func() {
    33  		if setupErr != nil {
    34  			if err := os.RemoveAll(localPath); err != nil {
    35  				logrus.Errorf("error cleaning up config dir: %s", err)
    36  			}
    37  		}
    38  	}()
    39  
    40  	if c.DependencyStore == nil {
    41  		return fmt.Errorf("config store is not initialized")
    42  	}
    43  
    44  	for _, configRef := range c.ConfigReferences {
    45  		// TODO (ehazlett): use type switch when more are supported
    46  		if configRef.File == nil {
    47  			// Runtime configs are not mounted into the container, but they're
    48  			// a valid type of config so we should not error when we encounter
    49  			// one.
    50  			if configRef.Runtime == nil {
    51  				logrus.Error("config target type is not a file or runtime target")
    52  			}
    53  			// However, in any case, this isn't a file config, so we have no
    54  			// further work to do
    55  			continue
    56  		}
    57  
    58  		fPath, err := c.ConfigFilePath(*configRef)
    59  		if err != nil {
    60  			return errors.Wrap(err, "error getting config file path for container")
    61  		}
    62  		log := logrus.WithFields(logrus.Fields{"name": configRef.File.Name, "path": fPath})
    63  
    64  		log.Debug("injecting config")
    65  		config, err := c.DependencyStore.Configs().Get(configRef.ConfigID)
    66  		if err != nil {
    67  			return errors.Wrap(err, "unable to get config from config store")
    68  		}
    69  		if err := ioutil.WriteFile(fPath, config.Spec.Data, configRef.File.Mode); err != nil {
    70  			return errors.Wrap(err, "error injecting config")
    71  		}
    72  	}
    73  
    74  	return nil
    75  }
    76  
    77  func (daemon *Daemon) setupIpcDirs(container *container.Container) error {
    78  	return nil
    79  }
    80  
    81  // TODO Windows: Fix Post-TP5. This is a hack to allow docker cp to work
    82  // against containers which have volumes. You will still be able to cp
    83  // to somewhere on the container drive, but not to any mounted volumes
    84  // inside the container. Without this fix, docker cp is broken to any
    85  // container which has a volume, regardless of where the file is inside the
    86  // container.
    87  func (daemon *Daemon) mountVolumes(container *container.Container) error {
    88  	return nil
    89  }
    90  
    91  func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
    92  	if len(c.SecretReferences) == 0 {
    93  		return nil
    94  	}
    95  
    96  	localMountPath, err := c.SecretMountPath()
    97  	if err != nil {
    98  		return err
    99  	}
   100  	logrus.Debugf("secrets: setting up secret dir: %s", localMountPath)
   101  
   102  	// create local secret root
   103  	if err := system.MkdirAllWithACL(localMountPath, 0, system.SddlAdministratorsLocalSystem); err != nil {
   104  		return errors.Wrap(err, "error creating secret local directory")
   105  	}
   106  
   107  	defer func() {
   108  		if setupErr != nil {
   109  			if err := os.RemoveAll(localMountPath); err != nil {
   110  				logrus.Errorf("error cleaning up secret mount: %s", err)
   111  			}
   112  		}
   113  	}()
   114  
   115  	if c.DependencyStore == nil {
   116  		return fmt.Errorf("secret store is not initialized")
   117  	}
   118  
   119  	for _, s := range c.SecretReferences {
   120  		// TODO (ehazlett): use type switch when more are supported
   121  		if s.File == nil {
   122  			logrus.Error("secret target type is not a file target")
   123  			continue
   124  		}
   125  
   126  		// secrets are created in the SecretMountPath on the host, at a
   127  		// single level
   128  		fPath, err := c.SecretFilePath(*s)
   129  		if err != nil {
   130  			return err
   131  		}
   132  		logrus.WithFields(logrus.Fields{
   133  			"name": s.File.Name,
   134  			"path": fPath,
   135  		}).Debug("injecting secret")
   136  		secret, err := c.DependencyStore.Secrets().Get(s.SecretID)
   137  		if err != nil {
   138  			return errors.Wrap(err, "unable to get secret from secret store")
   139  		}
   140  		if err := ioutil.WriteFile(fPath, secret.Spec.Data, s.File.Mode); err != nil {
   141  			return errors.Wrap(err, "error injecting secret")
   142  		}
   143  	}
   144  
   145  	return nil
   146  }
   147  
   148  func killProcessDirectly(container *container.Container) error {
   149  	return nil
   150  }
   151  
   152  func isLinkable(child *container.Container) bool {
   153  	return false
   154  }
   155  
   156  func enableIPOnPredefinedNetwork() bool {
   157  	return true
   158  }
   159  
   160  // serviceDiscoveryOnDefaultNetwork indicates if service discovery is supported on the default network
   161  func serviceDiscoveryOnDefaultNetwork() bool {
   162  	return true
   163  }
   164  
   165  func (daemon *Daemon) setupPathsAndSandboxOptions(container *container.Container, sboxOptions *[]libnetwork.SandboxOption) error {
   166  	return nil
   167  }
   168  
   169  func (daemon *Daemon) initializeNetworkingPaths(container *container.Container, nc *container.Container) error {
   170  
   171  	if nc.HostConfig.Isolation.IsHyperV() {
   172  		return fmt.Errorf("sharing of hyperv containers network is not supported")
   173  	}
   174  
   175  	container.NetworkSharedContainerID = nc.ID
   176  
   177  	if nc.NetworkSettings != nil {
   178  		for n := range nc.NetworkSettings.Networks {
   179  			sn, err := daemon.FindNetwork(n)
   180  			if err != nil {
   181  				continue
   182  			}
   183  
   184  			ep, err := getEndpointInNetwork(nc.Name, sn)
   185  			if err != nil {
   186  				continue
   187  			}
   188  
   189  			data, err := ep.DriverInfo()
   190  			if err != nil {
   191  				continue
   192  			}
   193  
   194  			if data["GW_INFO"] != nil {
   195  				gwInfo := data["GW_INFO"].(map[string]interface{})
   196  				if gwInfo["hnsid"] != nil {
   197  					container.SharedEndpointList = append(container.SharedEndpointList, gwInfo["hnsid"].(string))
   198  				}
   199  			}
   200  
   201  			if data["hnsid"] != nil {
   202  				container.SharedEndpointList = append(container.SharedEndpointList, data["hnsid"].(string))
   203  			}
   204  		}
   205  	}
   206  
   207  	return nil
   208  }