Browse code

Properly handle containers which pre-date the resolv.conf update feature

This fixes the container start issue for containers which were started
on a daemon prior to the resolv.conf updater PR. The update code will
now safely ignore these containers (given they don't have a sha256 hash
to compare against) and will not attempt to update the resolv.conf
through their lifetime.

Docker-DCO-1.1-Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com> (github: estesp)

Phil Estes authored on 2015/01/10 11:18:57
Showing 2 changed files
... ...
@@ -1057,7 +1057,15 @@ func (container *Container) updateResolvConf(updatedResolvConf []byte, newResolv
1057 1057
 	//read the hash from the last time we wrote resolv.conf in the container
1058 1058
 	hashBytes, err := ioutil.ReadFile(resolvHashFile)
1059 1059
 	if err != nil {
1060
-		return err
1060
+		if !os.IsNotExist(err) {
1061
+			return err
1062
+		}
1063
+		// backwards compat: if no hash file exists, this container pre-existed from
1064
+		// a Docker daemon that didn't contain this update feature. Given we can't know
1065
+		// if the user has modified the resolv.conf since container start time, safer
1066
+		// to just never update the container's resolv.conf during it's lifetime which
1067
+		// we can control by setting hashBytes to an empty string
1068
+		hashBytes = []byte("")
1061 1069
 	}
1062 1070
 
1063 1071
 	//if the user has not modified the resolv.conf of the container since we wrote it last
... ...
@@ -201,6 +201,13 @@ If the options (`--dns` or `--dns-search`) have been used to modify the
201 201
 default host configuration, then the replacement with an updated host's
202 202
 `/etc/resolv.conf` will not happen as well.
203 203
 
204
+> **Note**:
205
+> For containers which were created prior to the implementation of
206
+> the `/etc/resolv.conf` update feature in Docker 1.5.0: those
207
+> containers will **not** receive updates when the host `resolv.conf`
208
+> file changes. Only containers created with Docker 1.5.0 and above
209
+> will utilize this auto-update feature.
210
+
204 211
 ## Communication between containers and the wider world
205 212
 
206 213
 <a name="the-world"></a>