mirror of
https://github.com/Websoft9/websoft9.git
synced 2025-01-23 09:12:59 +08:00
docker
This commit is contained in:
parent
dd66f49cc3
commit
34e0cce673
@ -15,4 +15,8 @@
|
|||||||
|
|
||||||
#### 如何获取所有已占用的端口号?
|
#### 如何获取所有已占用的端口号?
|
||||||
|
|
||||||
基于 psutil 模块打印所有端口信息,然后匹配关键词
|
基于 psutil 模块打印所有端口信息,然后匹配关键词
|
||||||
|
|
||||||
|
#### 是否可以直接使用 Linux 命令?
|
||||||
|
|
||||||
|
为了提高操作系统的兼容性,尽量减少 Linux 命令使用,可以多使用 Python 包处理 Docker
|
17
cli/model.py
17
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
|
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
|
||||||
|
|
||||||
import urllib.request
|
import urllib.request
|
||||||
@ -157,6 +157,17 @@ class DockerComposeOp:
|
|||||||
class DockerOp:
|
class DockerOp:
|
||||||
''' Docker operation '''
|
''' Docker operation '''
|
||||||
def __init__(self):
|
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
|
typer
|
||||||
psutil
|
psutil
|
||||||
jq
|
pyjq
|
||||||
docker
|
docker
|
||||||
docker-compose
|
docker-compose
|
@ -1,5 +1,4 @@
|
|||||||
import docker
|
import model
|
||||||
|
docker = model.DockerOp()
|
||||||
|
|
||||||
client = docker.from_env()
|
docker.lsProject()
|
||||||
for image in client.images.list():
|
|
||||||
print(image.id)
|
|
Loading…
Reference in New Issue
Block a user