fussybeaver / bollard

Docker daemon API in Rust
Apache License 2.0
907 stars 134 forks source link

Strange difference in behaviour between docker import and importing via the API #447

Open Nereuxofficial opened 3 months ago

Nereuxofficial commented 3 months ago

I recently added this crate to my project to deal with the docker API and it works really well and has a lot of documentation, which is great!

However i noticed a weird difference in behaviour between the docker import command and importing using this crate. I have a fairly small container started using this command:

docker run -d --name looper busybox /bin/sh -c 'i=0; while true; do echo $i; i=$(expr $i + 1); sleep 1; done'

and created an image for it using docker export(also works via the crate fine in my testing).

However importing the archive fails with this error, which indicates a missing file:

called `Result::unwrap()` on an `Err` value: DockerStreamError { error: "open /home/bene/.local/share/docker/tmp/docker-import-1868653418/bin/json: no such file or directory" }

This file is not present in the archive as far as i can see, however importing it using docker import works just fine. Now it may well be that this bug is due to a mistake I've made during the implementation but i could not yet find it so any help would be appreciated :)

I have created a reproduction example in a fork of this repo, which also has an example file to import it. Running it should be as simple as:

git clone https://github.com/Nereuxofficial/bollard
git checkout import_bug
cargo r --example import_image

And via docker:

docker import looper.tar.gz

On another note i also noticed that the example code for importing is incorrect and errors out with an EOF error, probably due to only parsing the first chunk. I will later create a PR for that if it is something that should be fixed.

fussybeaver commented 3 months ago

It looks like the looper tarball was created with container_export or the docker container export command, which is not the same as the image export facility. The former exports the FS, while the latter is exporting the image and related metadata..