Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions packages/dashmate/src/listr/tasks/ssl/VerificationServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,29 +97,36 @@ export default class VerificationServer {

await this.dockerPull(image);

try {
this.container = await this.docker.createContainer(opts);
} catch (e) {
if (e.statusCode === 409) {
let retries = 0;
const MAX_RETRIES = 3;
while (!this.container && retries <= MAX_RETRIES) {
try {
this.container = await this.docker.createContainer(opts);
} catch (e) {
// Throw any other error except container name conflict
if (e.statusCode !== 409) {
throw e;
}

// Container name is already in use

// Remove container
const danglingContainer = await this.docker.getContainer(name);

await danglingContainer.remove({ force: true });

try {
await danglingContainer.wait();
} catch (waitError) {
// Skip error if container is already removed
if (e.statusCode !== 404) {
throw e;
// Throw any other error except container not found
if (waitError.statusCode !== 404) {
throw waitError;
}
}

// Try to create a container one more type
this.container = await this.docker.createContainer(opts);
// Skip error if container is already removed
}
}

throw e;
retries++;
}

this.startedContainers.addContainer(opts.name);
Expand Down
Loading