Search code examples
pythondockercontainersdockerpy

Run docker container with image name docker-py


I want to be able to run my docker container from inside docker-py, but when I pass a name to the function it gives me an error.

Stripped down version of my code:

image = "test_container"
client.containers.run(image=image)

Error:

 File "/home/user/.local/lib/python3.5/site-packages/docker/models/containers.py", line 799, in run
    [line for line in out]
TypeError: sequence item 0: expected a bytes-like object, str found

Can't seem to get it to work no matter what I do, it has worked elsewhere so this is strange.

It's worth noting that I'm running this over the balena socket, so it's not straight docker-py -> docker interface which could be adding to the issue, or is just a red herring.

I know that string representations have changed between python versions, this is with python3 if that is relevant.

Even stranger is that it (sometimes) runs the container anyway, despite the error. The only time it doesn't work is when I use a :tag at the end.


Solution

  • Not sure what happened. Rebooted, checked the spelling (image name was spelled wrong) and now it works. I'm sure the misspelling contributed, but I can't seem to replicate the error. Answering just to try to help anyone else that comes along after me.