Dockerode: Cancel image building

Created on 20 Jul 2016  路  3Comments  路  Source: apocas/dockerode

Hi,
I'm searching a way to cancel an image building but I don't find solution currently. I try to cancel building but I think this is the same problem to cancel others operations like pulling images, pushing...

The only way I found to cancel the build is by adding the option openStdin: true in the method buildImage to have a HttpDuplex object. Then I can call destroy to break the http request and cancel the building.

Is that a good solution for a pull request or it will be another way to do that.

question

Most helpful comment

Hi,
Somethink like that:

var Docker = require('dockerode');
var docker = new Docker();

var tarStream = tar.pack(process.cwd());
docker.buildImage(tarStream, {
  t: 'imgcwd',
  openStdin: true, // To have a HttpDuplex object
}, function(error, stream) {
  if (error) {
    return console.error(error);
  }
  stream.on('end', () => { console.log('end'); }):
  stream.on('error', (error) => { console.error(error); }):
  stream.on('data', (data) => { console.log(data); }):

  setTimeout(() => {
   // Cancel build after 5 secs
    stream.destroy();
  }, 5000);
});

All 3 comments

@gaetsd Do you happen to have an example of how you've achieved the cancellation?

Hi,
Somethink like that:

var Docker = require('dockerode');
var docker = new Docker();

var tarStream = tar.pack(process.cwd());
docker.buildImage(tarStream, {
  t: 'imgcwd',
  openStdin: true, // To have a HttpDuplex object
}, function(error, stream) {
  if (error) {
    return console.error(error);
  }
  stream.on('end', () => { console.log('end'); }):
  stream.on('error', (error) => { console.error(error); }):
  stream.on('data', (data) => { console.log(data); }):

  setTimeout(() => {
   // Cancel build after 5 secs
    stream.destroy();
  }, 5000);
});

That's great @gaetsd will try it out, thank you.

Was this page helpful?
0 / 5 - 0 ratings