Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Use alternative mechanism to list containers
Browse files Browse the repository at this point in the history
  • Loading branch information
sargun committed Nov 6, 2018
1 parent 5127390 commit a116ab5
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions executor/runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,12 +762,21 @@ func (r *DockerRuntime) doSetupSSHdContainer(ctx context.Context, containerName
noAts := strings.Replace(noDashes, "@", "-", -1)
noSlashes := strings.Replace(noAts, "/", "_", -1)
*containerName = "titus-sshd-" + noSlashes
_, err = r.client.ContainerInspect(ctx, *containerName)
if err == nil {

args := filters.NewArgs()
args.Add("name", *containerName)
containerListOptions := types.ContainerListOptions{
All: true,
Limit: 1,
Filters: args,
}

containers, err := r.client.ContainerList(ctx, containerListOptions)
if err != nil {
return nil
}

if !docker.IsErrNotFound(err) {
if len(containers) == 1 {
return err
}

Expand All @@ -787,9 +796,12 @@ func (r *DockerRuntime) doSetupSSHdContainer(ctx context.Context, containerName
// to prevent us from accidentally calling this concurrently
_, tmpErr := r.client.ContainerCreate(ctx, cfg, hostConfig, nil, *containerName)

_, err = r.client.ContainerInspect(ctx, *containerName)
if err == nil {
return nil
containers, err = r.client.ContainerList(ctx, containerListOptions)
if err != nil {
return err
}
if len(containers) != 1 {
err = fmt.Errorf("Could not make container %s", *containerName)
}
// Wait, there was probably an issue creating the container, if we weren't able to inspect the container
// if so, let's return an error
Expand Down

0 comments on commit a116ab5

Please sign in to comment.