I want to create a container and then run a command. Is this possible using python docker apis ?
I was able to create the container but I was not sure how to run a command inside that container.. does anybody know ? if I use run , it creates another container to run the command but I wanted to run in the same container.
The below throws "cannot exec in a stopped state: unknown"
I know one way to do is using 'cat' command and keep the container running but thats not ideal.
def createContainer(image, cmd, **kwargs):
container = dockerClient.containers.create(image=image, command=None,
**kwargs)
return container
def startContainer(container, **kwargs):
container.start(**kwargs)
def runCommand(container, cmd):
res = container.exec_run(cmd)
print res.output