mirror of
https://github.com/Websoft9/websoft9.git
synced 2024-11-24 00:20:24 +00:00
docker
This commit is contained in:
parent
dd66f49cc3
commit
34e0cce673
4 changed files with 23 additions and 9 deletions
|
@ -16,3 +16,7 @@
|
|||
#### 如何获取所有已占用的端口号?
|
||||
|
||||
基于 psutil 模块打印所有端口信息,然后匹配关键词
|
||||
|
||||
#### 是否可以直接使用 Linux 命令?
|
||||
|
||||
为了提高操作系统的兼容性,尽量减少 Linux 命令使用,可以多使用 Python 包处理 Docker
|
15
cli/model.py
15
cli/model.py
|
@ -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)
|
|
@ -1,5 +1,5 @@
|
|||
typer
|
||||
psutil
|
||||
jq
|
||||
pyjq
|
||||
docker
|
||||
docker-compose
|
|
@ -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()
|
Loading…
Reference in a new issue