question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docker build output is not iterable

See original GitHub issue
from io import BytesIO
import docker
dockerfile = '''
FROM ubuntu
RUN apt-get update
'''
f = BytesIO(dockerfile.encode('utf-8'))
client = docker.from_env()
for line in client.images.build(fileobj=f, rm=True, tag='test', nocache=True, stream=True):
    print(line)

From the documentation, it seems like I client.images.build should return a generator. I get the following traceback:

Traceback (most recent call last):
  File "issue_no_logs.py", line 9, in <module>
    for line in client.images.build(fileobj=f, rm=True, tag='test', nocache=True, stream=True):
TypeError: 'Image' object is not iterable
pip freeze | grep docker && python --version && docker version
docker==2.0.1
docker-pycreds==0.2.1
Python 2.7.12
Client:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.2
 Git commit:   6b644ec
 Built:        Mon, 19 Dec 2016 09:20:48 +1300
 OS/Arch:      linux/amd64
Server:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.2
 Git commit:   6b644ec
 Built:        Mon, 19 Dec 2016 09:20:48 +1300
 OS/Arch:      linux/amd64

cat /etc/os-release

NAME="Ubuntu"
VERSION="16.04.1 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.1 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

7reactions
shin-commented, Jan 20, 2017

Ah, this is a mistake - the stream parameter doesn’t do anything (it’s deprecated as noted). For streaming build logs, you’ll want the low-level build method on APIClient (client.api.build). http://docker-py.readthedocs.io/en/stable/api.html#module-docker.api.build

0reactions
is-unixcommented, Feb 2, 2018

I recently ran into this issue, however the reason was not because the docs were wrong, but because I had previously installed docker-py, I’m assuming as a pre-requisite of docker-compose and it was conflicting with the newer docker pip package. I discovered this after I ran into further issues when pushing the image (see this issue)

Prior to removing docker-py, the following code would throw the error TypeError: 'Image' object is not iterable. Now that it has been removed and replaced with the docker pip package, all is well.

import docker
client = docker.from_env()

i,log = client.images.build(path=cwd)
for line in log:
    print line
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is docker build not showing any output from commands?
When I run docker build . I don't see any output from these two commands even if they are not cached. The documentation...
Read more >
Docker Cache – How to Do a Clean Image Rebuild and Clear ...
The most popular container platform is Docker. This tutorial will explain how to use the Docker build cache to your advantage.
Read more >
Python map() function - DigitalOcean
Python map() function is used to apply a function on all the elements of specified iterable and return map object. Python map object...
Read more >
typeerror: object is not iterable (cannot read property symbol ...
This error usually occurs when you try to iterate (for example, using a for loop) on an object which is not iterable (for...
Read more >
What does . mean in docker? Does it mean the current ...
It means, take the file theapp.py and copy it to the working directory of the docker image that is being built. This directory...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found