Skip to content

Commit d37d483

Browse files
committed
docker-container: avoid fail if container conflict
Fixes the race condition where two boots are executed simultaneously across multiple processes. We initially check to see if the container exists, but if during container creation we get a name conflict, we don't treat this error as a hard failure, and instead move immediately into waiting for the node to boot. Signed-off-by: Justin Chadwell <me@jedevc.com>
1 parent e5419ef commit d37d483

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

driver/docker-container/driver.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/docker/docker/api/types/mount"
2323
"github.com/docker/docker/api/types/network"
2424
dockerclient "github.com/docker/docker/client"
25+
"github.com/docker/docker/errdefs"
2526
dockerarchive "github.com/docker/docker/pkg/archive"
2627
"github.com/docker/docker/pkg/idtools"
2728
"github.com/docker/docker/pkg/stdcopy"
@@ -148,14 +149,16 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error {
148149

149150
}
150151
_, err := d.DockerAPI.ContainerCreate(ctx, cfg, hc, &network.NetworkingConfig{}, nil, d.Name)
151-
if err != nil {
152-
return err
153-
}
154-
if err := d.copyToContainer(ctx, d.InitConfig.Files); err != nil {
152+
if err != nil && !errdefs.IsConflict(err) {
155153
return err
156154
}
157-
if err := d.start(ctx, l); err != nil {
158-
return err
155+
if err == nil {
156+
if err := d.copyToContainer(ctx, d.InitConfig.Files); err != nil {
157+
return err
158+
}
159+
if err := d.start(ctx, l); err != nil {
160+
return err
161+
}
159162
}
160163
if err := d.wait(ctx, l); err != nil {
161164
return err

0 commit comments

Comments
 (0)