docker: fix container missing after restarting dockerd twice

fix #I6MJ4X

(cherry picked from commit c449de66430e0546323a3b63f1ba78c449b077da)
This commit is contained in:
JackChan8 2023-03-14 17:14:44 +08:00 committed by openeuler-sync-bot
parent 43168916ff
commit 63617251b6
4 changed files with 71 additions and 2 deletions

View File

@ -1 +1 @@
18.09.0.249
18.09.0.250

View File

@ -1,6 +1,6 @@
Name: docker-engine
Version: 18.09.0
Release: 249
Release: 250
Epoch: 1
Summary: The open-source application container engine
Group: Tools/Docker
@ -199,6 +199,12 @@ fi
%endif
%changelog
* Wed Mar 14 2023 chenjiankun<chenjiankun1@huawei.com>- 18.09.0-250
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:fix container missing after restarting dockerd twice
* Fri Feb 17 2023 chenjiankun<chenjiankun1@huawei.com>- 18.09.0-249
- Type:bugfix
- CVE:NA

View File

@ -0,0 +1,62 @@
From 199481834e9e8e1ab4debaae737f372ac295af22 Mon Sep 17 00:00:00 2001
From: chenjiankun <chenjiankun1@huawei.com>
Date: Fri, 17 Feb 2023 15:06:07 +0800
Subject: [PATCH] docker: fix container missing after restarting dockerd twice
when restart dockerd and restore containers, if "no space left on device"
in /var/lib/docker, daemon.Register will failed, and then dockerd will
cleanup the init and rootfs layer. then if we restart dockerd again, dockerd
will remove container dir for daemon.imageService.GetLayerByID failed. Then
the container will disappear forever.
---
components/engine/daemon/container.go | 12 +++++++++++-
components/engine/daemon/daemon.go | 15 ++++++++++-----
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/components/engine/daemon/daemon.go b/components/engine/daemon/daemon.go
index 6e3477bf5..96cfb14bf 100644
--- a/components/engine/daemon/daemon.go
+++ b/components/engine/daemon/daemon.go
@@ -311,10 +311,17 @@ func (daemon *Daemon) restore() error {
removeContainers := make(map[string]*container.Container)
restartContainers := make(map[*container.Container]chan struct{})
activeSandboxes := make(map[string]interface{})
+
+ containerIDs := make(map[string]struct{})
+ for cid, _ := range containers {
+ containerIDs[cid] = struct{}{}
+ }
+
for id, c := range containers {
if err := daemon.registerName(c); err != nil {
logrus.Errorf("Failed to register container name %s: %s", c.ID, err)
delete(containers, id)
+ delete(containerIDs, id)
continue
}
@@ -325,6 +332,9 @@ func (daemon *Daemon) restore() error {
if err := daemon.Register(c); err != nil {
logrus.Errorf("Failed to register container %s: %s", c.ID, err)
delete(containers, id)
+ if !strings.Contains(err.Error(), "no space left on device") {
+ delete(containerIDs, id)
+ }
continue
}
@@ -528,11 +538,6 @@ func (daemon *Daemon) restore() error {
logrus.Errorf("removeRedundantMounts failed %v", err)
}
- containerIDs := make(map[string]struct{})
- for cid, _ := range containers {
- containerIDs[cid] = struct{}{}
- }
-
err = daemon.imageService.LayerStoreForOS(runtime.GOOS).CleanupRedundant(containerIDs)
if err != nil {
logrus.Errorf("cleanup redundant IDs in layerStore failed %s", err)
--
2.33.0

View File

@ -229,4 +229,5 @@ patch/0232-docker-cleanup-netns-file-when-close-docker-daemon.patch
patch/0233-docker-Read-connection-marking-information-from-CT-f.patch
patch/0234-docker-do-not-stop-health-check-before-sending-signa.patch
patch/0235-docker-set-freezer.state-to-Thawed-to-increase-freez.patch
patch/0236-docker-fix-container-missing-after-restarting-docker.patch
#end