0
votes

I want to download image as a blob or tar from Docker, to push somewhere as a file. Using docker-registry-client in NodeJS with method createBlobReadStream, somwhow take blob file but it is only conf file of image.

    async function createReadStream(DIGEST) {
    client.createBlobReadStream({ digest: DIGEST }, function (err, stream) {
        if (err) {
            console.log(err)
            client.close();
            return
        }
        console.log('Got a digest %s', DIGEST);
        var fout = fs.createWriteStream(`//wsl$//docker-desktop-data//version-pack-data//community//docker//image//overlay2//imagedb//content//sha256//blob-${DIGEST}.file`);
        fout.on('finish', function () {
            console.log('Done downloading blob', DIGEST);
        });
        fout.on('error', function (err) {
            console.log(err)
        })
        stream.pipe(fout);
        stream.resume();
        client.close();
    })
}

There is addittional things I should mention:

  1. All actions done in Windows 10, Docker with Linux containers
  2. NodeJS as platform and docker-registry-client as library.
  3. Docker data stores in ext4.vhdx

Where to extract blob or tar of just created Docker image with NodeJS?

Sorry if my question looks stupid, but since docker is installed on your machine, why don't you simply do this with the docker command directly? => docker image pull my_image:my_tag && docker image save my_image:my_tag -o my_image-my_tag.tar. Doing this through you above api will require much more than a single simple blob download (get manifest, parse all layers, get them individually, package the result....). Is it really worth re-implementing a full docker client you already have if saving an image content is your only requirement? - Zeitounator
Yes, if I only wanted to download the image then your solution is correct. But I want to write a tool to download and push to a different register. Doing this through you above api will require much more than a single simple blob download (get manifest, parse all layers, get them individually, package the result....). Do you know how to do it in NodeJS? - Zethuman
Does it have to be a native nodejs program using that library? Could it be a compiled binary that you exec from nodejs? Do you want to support multi-platform images? - BMitch
Does it have to be a native nodejs program using that library? Yes Could it be a compiled binary that you exec from nodejs? Maybe, because I can create webui in future Do you want to support multi-platform images? No - Zethuman
Do you know how to do it in NodeJS? <= no but I basically gave you the global recipe in my very first comment. - Zeitounator