Prechádzať zdrojové kódy

Adapt container settings when start

`adaptContainerSettings` is growing up, new it's only called
when create. It'll be a problem that old containers will never
have chance to adapt the latest rule. `HostConfig` of these
containers will be obsoleted.

Add this calling to start to avoid problems like #18550 and
avoid such backward compatability in the future.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Qiang Huang 9 rokov pred
rodič
commit
f408b4f463
1 zmenil súbory, kde vykonal 5 pridanie a 3 odobranie
  1. 5 3
      daemon/start.go

+ 5 - 3
daemon/start.go

@@ -30,9 +30,6 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf
 		// creating a container, not during start.
 		// creating a container, not during start.
 		if hostConfig != nil {
 		if hostConfig != nil {
 			logrus.Warn("DEPRECATED: Setting host configuration options when the container starts is deprecated and will be removed in Docker 1.12")
 			logrus.Warn("DEPRECATED: Setting host configuration options when the container starts is deprecated and will be removed in Docker 1.12")
-			if err := daemon.adaptContainerSettings(hostConfig, false); err != nil {
-				return err
-			}
 			if err := daemon.setHostConfig(container, hostConfig); err != nil {
 			if err := daemon.setHostConfig(container, hostConfig); err != nil {
 				return err
 				return err
 			}
 			}
@@ -49,6 +46,11 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf
 	if _, err = daemon.verifyContainerSettings(container.HostConfig, nil); err != nil {
 	if _, err = daemon.verifyContainerSettings(container.HostConfig, nil); err != nil {
 		return err
 		return err
 	}
 	}
+	// Adapt for old containers in case we have updates in this function and
+	// old containers never have chance to call the new function in create stage.
+	if err := daemon.adaptContainerSettings(container.HostConfig, false); err != nil {
+		return err
+	}
 
 
 	if err := daemon.containerStart(container); err != nil {
 	if err := daemon.containerStart(container); err != nil {
 		return err
 		return err