Skip to content

Commit a328bbc

Browse files
committed
bugfix: cannot get restartCount/ let restartCount++ after restart a container
1 parent 98d107f commit a328bbc

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

apis/server/container_bridge.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ func (s *Server) getContainer(ctx context.Context, rw http.ResponseWriter, req *
7474
}
7575

7676
container := types.ContainerJSON{
77-
ID: c.ID,
78-
Name: c.Name,
79-
Image: c.Config.Image,
80-
Created: c.Created,
81-
State: c.State,
82-
Config: c.Config,
83-
HostConfig: c.HostConfig,
84-
Snapshotter: c.Snapshotter,
77+
ID: c.ID,
78+
Name: c.Name,
79+
Image: c.Config.Image,
80+
Created: c.Created,
81+
State: c.State,
82+
Config: c.Config,
83+
HostConfig: c.HostConfig,
84+
Snapshotter: c.Snapshotter,
85+
RestartCount: c.RestartCount,
8586
GraphDriver: &types.GraphDriverData{
8687
Name: c.Snapshotter.Name,
8788
Data: c.Snapshotter.Data,

daemon/mgr/container.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,20 @@ func (mgr *ContainerManager) Restart(ctx context.Context, name string, timeout i
796796
}
797797

798798
logrus.Debugf("start container %s when restarting", c.ID)
799+
800+
//let restartCount++
801+
restartCount := c.RestartCount + 1
802+
799803
// start container
800-
return mgr.start(ctx, c, &types.ContainerStartOptions{})
804+
err = mgr.start(ctx, c, &types.ContainerStartOptions{})
805+
if err != nil {
806+
return err
807+
}
808+
809+
c.RestartCount = restartCount
810+
811+
logrus.Debugf("container %s restartCount is %d", c.ID, c.RestartCount)
812+
return c.Write(mgr.Store)
801813
}
802814

803815
// Pause pauses a running container.

0 commit comments

Comments
 (0)