我的目标是仅在尚未运行的容器上运行。
我尝试使用client.containers.get(containername)并检查它是否为None,但这将无法工作,因为它会返回错误消息而不是bool。
if client.containers.get('containername') is not None: client.containeres.run("redis:latest",name="containerename", detach=True, ports={'6379/tcp': ('localhost', 6379)})
我得到:
docker.error.notFound: 404 Client Error: Not Found("No such container: containername")
有什么方法可以检查redis容器是否已经在运行,如果没有运行,请仅运行该容器?
我的目标是仅在尚未运行的容器上运行。我试过的是使用client.containers.get(containername)并检查它是否为None,但由于返回错误而无法使用...
如何使用containers.list?