Docker小工具
原由
- 由于最近程序选封装成docker,后需要查看日志和进入和重启容器,需要知道dockerID 或者容器名称,还需要鼠标记录复制,避免麻烦,才触发该脚本
源代码
#!/usr/bin/python3
# -*- coding:utf-8 -*-
import docker,os
client = docker.from_env()
# client = docker.DockerClient("http://127.0.0.1:2375")
docker_containerid_list = []
docker_containerName_list = []
docker_index = 0
print("Please use the root user")
print("Current Docker Container Running List: ")
print("=========================================================")
for container in client.containers.list():
#print(dir(container))
container_id = str(container.id)[0:11]
container_name = str(container.name)
#print("docker index: ",str(docker_index)," ",container.name," ",container_id," ",container.ports)
print("docker index: \033[1;31m" + str(docker_index) + "\033[0m"," \033[1;35m",container