docker-py api client.images.load fails but the cli client works fine

Created on 4 Jun 2018  路  4Comments  路  Source: docker/docker-py

Used docker save to create tar file of my docker image. Now when i try to load this archived image file using docker python api images.load, it fails with below error. But the cli client command "docker load" works for the same tar file. Can you please help me debug this issue ?

client.images.load("rootfs.tar")
Traceback (most recent call last):
File "", line 1, in
File "docker/models/images.py", line 368, in load
raise ImageLoadError(chunk['error'])
docker.errors.ImageLoadError: Error processing tar file(exit status 1): unexpected EOF

$ docker load -i rootfs.tar
432b65032b94: Loading layer [==================================================>] 1.36MB/1.36MB
Loaded image: busybox:latest

kinquestion

Most helpful comment

with open(tarpath, 'r') as f: client.images.load(f)

This didn't work. I had to open the tar files in binary mode like so:

with open(tarpath, 'rb') as f: client.images.load(f)

All 4 comments

usage error, input parameter should be data, not filename.
http://docker-py.readthedocs.io/en/stable/images.html
Open file and pass in file handle

@sureshsankaran Did you find a solution?
I have tried two things:
client.images.load(tarurl)
and
client.images.build(fileobj = tarurl,custom_context = True)

Both of them do notwork. Following are the errors:
docker.errors.ImageLoadError: Error processing tar file(exit status 1): unexpected EOF
and
docker.errors.APIError: 500 Server Error: Internal Server Error ("unexpected EOF")

@ramkrishnan8994 Please read the documentation.

with open(tarpath, 'r') as f:
  client.images.load(f)

with open(tarpath, 'r') as f: client.images.load(f)

This didn't work. I had to open the tar files in binary mode like so:

with open(tarpath, 'rb') as f: client.images.load(f)

Was this page helpful?
0 / 5 - 0 ratings