[英]Check the status of the container in Github repo
I have a repo in guthub and there are shared containers(folders) in them.我在guthub 中有一个repo,其中有共享容器(文件夹)。 I need to pass the container name and check if it is running.我需要传递容器名称并检查它是否正在运行。 I have a script in place as mentioned below:我有一个脚本,如下所述:
from typing import Optional
import docker
def is_container_running(container_name: str) -> Optional[bool]:
RUNNING = "running"
docker_client = docker.from_env()
try:
container = docker_client.containers.get(container_name)
except docker.errors.NotFound as exc:
print(f"Check container name\n{exc.explanation}")
else:
container_state = container.attrs["State"]
return container_state["Status"] == RUNNING
if __name__ == "__main__":
container_name = "folder1"
result = is_container_running(container_name)
print(result)
This is the structure of the repo and I have created newfolder and new_script.py has the above python code.这是 repo 的结构,我创建了 newfolder 和 new_script.py 有上面的 python 代码。
my_repo
folder1
file1.py
Dockerfile
folder2
file1.py
Dockerfile
folder3
file1.py
file2.py
Dockerfile
newfolder
new_script.py
If I pass "folder1" in the container_name variable, Im getting this message:如果我在 container_name 变量中传递“folder1”,我会收到以下消息:
Check container name No such container: folder1 None
How do I need to check the status of the container in my repo?如何在我的仓库中检查容器的状态? Pls suggest.请建议。
A container can be run with any name.可以使用任何名称运行容器。
folder1
does not represent necessarily a container name, since we do not know what parameter was used for the docker run -t <aName>
command. folder1
不一定代表容器名称,因为我们不知道docker run -t <aName>
命令使用了什么参数。
But if it does, you could say that such an error ("No such container") means the status is "Not running".但如果是这样,您可以说这样的错误(“没有这样的容器”)意味着状态是“未运行”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.