@@ -24,19 +24,6 @@ import (
24
24
"github.com/coder/coder/v2/codersdk"
25
25
)
26
26
27
- // DockerCLILister is a ContainerLister that lists containers using the docker CLI
28
- type DockerCLILister struct {
29
- execer agentexec.Execer
30
- }
31
-
32
- var _ Lister = & DockerCLILister {}
33
-
34
- func NewDocker (execer agentexec.Execer ) Lister {
35
- return & DockerCLILister {
36
- execer : agentexec .DefaultExecer ,
37
- }
38
- }
39
-
40
27
// DockerEnvInfoer is an implementation of agentssh.EnvInfoer that returns
41
28
// information about a container.
42
29
type DockerEnvInfoer struct {
@@ -241,6 +228,19 @@ func run(ctx context.Context, execer agentexec.Execer, cmd string, args ...strin
241
228
return stdout , stderr , err
242
229
}
243
230
231
+ // DockerCLILister is a ContainerLister that lists containers using the docker CLI
232
+ type DockerCLILister struct {
233
+ execer agentexec.Execer
234
+ }
235
+
236
+ var _ Lister = & DockerCLILister {}
237
+
238
+ func NewDocker (execer agentexec.Execer ) Lister {
239
+ return & DockerCLILister {
240
+ execer : agentexec .DefaultExecer ,
241
+ }
242
+ }
243
+
244
244
func (dcl * DockerCLILister ) List (ctx context.Context ) (codersdk.WorkspaceAgentListContainersResponse , error ) {
245
245
var stdoutBuf , stderrBuf bytes.Buffer
246
246
// List all container IDs, one per line, with no truncation
@@ -319,9 +319,12 @@ func runDockerInspect(ctx context.Context, execer agentexec.Execer, ids ...strin
319
319
stdout = bytes .TrimSpace (stdoutBuf .Bytes ())
320
320
stderr = bytes .TrimSpace (stderrBuf .Bytes ())
321
321
if err != nil {
322
+ if bytes .Contains (stderr , []byte ("No such object:" )) {
323
+ // This can happen if a container is deleted between the time we check for its existence and the time we inspect it.
324
+ return stdout , stderr , nil
325
+ }
322
326
return stdout , stderr , err
323
327
}
324
-
325
328
return stdout , stderr , nil
326
329
}
327
330
0 commit comments