This commit is contained in:
chendelin1982 2021-10-17 22:47:15 +08:00
parent dd66f49cc3
commit 34e0cce673
4 changed files with 23 additions and 9 deletions

View file

@ -16,3 +16,7 @@
#### 如何获取所有已占用的端口号?
基于 psutil 模块打印所有端口信息,然后匹配关键词
#### 是否可以直接使用 Linux 命令?
为了提高操作系统的兼容性,尽量减少 Linux 命令使用,可以多使用 Python 包处理 Docker

View file

@ -1,5 +1,5 @@
import os, io, sys, platform, psutil, json, secrets, string
import os, io, sys, platform, psutil, json, secrets, string, docker
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
import urllib.request
@ -157,6 +157,17 @@ class DockerComposeOp:
class DockerOp:
''' Docker operation '''
def __init__(self):
pass
self.client = docker.from_env()
def lsContainer(self):
container_list = []
for container in self.client.containers.list(all):
container_list.append(container.name)
return container_list
def lsProject(self):
project_dict = {}
for name in self.lsContainer():
print(self.client.containers.get(name).labels)

View file

@ -1,5 +1,5 @@
typer
psutil
jq
pyjq
docker
docker-compose

View file

@ -1,5 +1,4 @@
import docker
import model
docker = model.DockerOp()
client = docker.from_env()
for image in client.images.list():
print(image.id)
docker.lsProject()