diff --git a/gulpfile.js b/gulpfile.js index dcb0aa6f1..dc95c24be 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -429,15 +429,22 @@ async function docker() { let result = await execP(`docker run --env RUN_CHOWN=${runChown} -d ${dockerArgs} salix-db`); containerId = result.stdout; - if (argv['random']) { - let inspect = await execP(`docker inspect -f "{{json .NetworkSettings}}" ${containerId}`); - let netSettings = JSON.parse(inspect.stdout); + try { + if (argv['random']) { + let inspect = await execP(`docker inspect -f "{{json .NetworkSettings}}" ${containerId}`); + let netSettings = JSON.parse(inspect.stdout); - dbConf.host = netSettings.Gateway; - dbConf.port = netSettings.Ports['3306/tcp'][0]['HostPort']; + dbConf.host = netSettings.Gateway; + dbConf.port = netSettings.Ports['3306/tcp'][0]['HostPort']; + } + + if (runChown) await dockerWait(); + } catch (err) { + if (argv['random']) + await execP(`docker rm -fv ${containerId}`); + throw err; } - if (runChown) await dockerWait(); return containerId; } docker.description = `Builds the database image and runs a container`;