Hi,
I'm trying to use pull in a promise but keep getting this error that haven't been able to track down.
This is the initial function:
function pull(service) {
var opts = {};
log.info('Pulling: %s', service.Image);
if (service.Image.indexOf('gcr.io') > -1) { // if the image is in gcr.io (ie: private)
opts.authconfig = auth; // add authconfig
};
return new Promise(function(resolve) {
docker.pull(service.Image, opts, function(err, stream){
docker.modem.followProgress(stream, function(err, out){
resolve(service);
}, function(event){
// log.info({ event: event }, 'Pull Progress:');
});
});
});
}
I call this like so (pseudo code to illustrate):
pull({Image: ''}).then(/*...*/);
Debug shows:
modem Sending: { path: '/images/create?authconfig=&fromImage=gcr.io...&tag=0.0.1',
method: 'POST',
headers:
{ 'X-Registry-Auth': '...',
'Content-Type': 'application/json',
'Content-Length': 177 },
key: <Buffer ... >,
cert: <Buffer ... >,
ca: <Buffer ... >,
hostname: '192.168.99.100',
port: '2376' } +8ms
modem Sending: { path: '/containers/create?Image=gcr.io...%3A0.0.1&name=db&Labels=&Hostname=db&ExposedPorts=&PortBindings=',
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Content-Length': 175 },
key: <Buffer ... >,
cert: <Buffer ... >,
ca: <Buffer ... >,
hostname: '192.168.99.100',
port: '2376' } +2ms
modem Received: No such image: gcr.io/...:0.0.1 (tag: 0.0.1)
+126ms
And then I get this error BUT the pulling does continue...
Unhandled rejection Error: HTTP code is 404 which indicates error: no such container - No such image: gcr.io...:0.0.1 (tag: 0.0.1)
at .../node_modules/docker-modem/lib/modem.js:230:17
at getCause (.../node_modules/docker-modem/lib/modem.js:258:7)
at Modem.buildPayload (.../node_modules/docker-modem/lib/modem.js:229:5)
at IncomingMessage.<anonymous> (.../node_modules/docker-modem/lib/modem.js:205:14)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at doNTCallback2 (node.js:452:9)
at process._tickCallback (node.js:366:17)
...eventually the pulling does complete but I want to handle that error correctly.
Notes:
Thank you very much for any help. I'll keep investigating on my side.
Note that I realize this is an error bubbling up because I am not handling the rejected promise... I just don't know where the error should be handled because I'm not sure how to handle it around dockerode.
Ok, solved it. Here's some info in case someone runs into the same issue:
When calling the pull function above, it is important to make sure you are handling the rejection error even if you don't do anything with it (more info). So I changed the call and made it:
pull({Image: 'gcr.io/.../.../'}).then(/*...*/).catch(function(e){});
it actually looks like this in my code where I'm chaining a number of promises:
pull(service).then(create).then(start).catch(function(e){});
which simply catches the error and ignores it. I'm adding better error handling as I type this but this should solve this issue here.
Thank you and sorry for the noise.
@lgomez I realize I'm 3 years to late but I just hit this problem and wasted a better part of a day debugging it. your solution worked wonders!
Most helpful comment
Ok, solved it. Here's some info in case someone runs into the same issue:
When calling the
pullfunction above, it is important to make sure you are handling the rejection error even if you don't do anything with it (more info). So I changed the call and made it:it actually looks like this in my code where I'm chaining a number of promises:
which simply catches the error and ignores it. I'm adding better error handling as I type this but this should solve this issue here.
Thank you and sorry for the noise.