How to run an container with specific tag docker-py

374 Views Asked by At

Trying to run a docker container from docker-py, but when I run: client.containers.run(image='my/image:tag')

I get this error:

TypeError: sequence item 0: expected a bytes-like object, str found

Encoding to bytes with:

client.containers.run(image='my/image:tag'.encode())

Gives the error:

TypeError: b'my/image:tag' is not JSON serializable

I've tried going through the run function to see if there's a tag keyword, but as far as I can tell there's not.

1

There are 1 best solutions below

1
On BEST ANSWER

Try running images.list() first and then use get to get the required image

Ex:

client.images.list()
#--> Should output all available Images

Then Run

container = client.images.get('Image_Name')   
container.stop()   #Stops Image.

This should give you exact image name.

container.attrs['Config']['Image']