mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Image: Always create a .docker-id file in the devices we create
Without this there is really no way to map back from the device-mapper devices to the actual docker image/container ids in case the json file somehow got lost
This commit is contained in:
parent
a9ec1dbc9b
commit
074f38d493
1 changed files with 18 additions and 0 deletions
18
image.go
18
image.go
|
@ -368,6 +368,13 @@ func (image *Image) ensureImageDevice(devices DeviceSet) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(path.Join(mountDir, ".docker-id"), []byte(image.ID), 0600)
|
||||||
|
if err != nil {
|
||||||
|
_ = devices.RemoveDevice(image.ID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
utils.Debugf("Applying layer %s at %s", image.ID, mountDir)
|
utils.Debugf("Applying layer %s at %s", image.ID, mountDir)
|
||||||
err = image.applyLayer(layerPath(root), mountDir)
|
err = image.applyLayer(layerPath(root), mountDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -427,12 +434,14 @@ func (image *Image) Mount(runtime *Runtime, root, rw string, id string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createdDevice := false
|
||||||
if !devices.HasDevice(id) {
|
if !devices.HasDevice(id) {
|
||||||
utils.Debugf("Creating device %s for container based on image %s", id, image.ID)
|
utils.Debugf("Creating device %s for container based on image %s", id, image.ID)
|
||||||
err = devices.AddDevice(id, image.ID)
|
err = devices.AddDevice(id, image.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
createdDevice = true
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.Debugf("Mounting container %s at %s for container", id, root)
|
utils.Debugf("Mounting container %s at %s for container", id, root)
|
||||||
|
@ -440,6 +449,15 @@ func (image *Image) Mount(runtime *Runtime, root, rw string, id string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if createdDevice {
|
||||||
|
err = ioutil.WriteFile(path.Join(root, ".docker-id"), []byte(id), 0600)
|
||||||
|
if err != nil {
|
||||||
|
_ = devices.RemoveDevice(image.ID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue