-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
36 lines (29 loc) · 980 Bytes
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import docker
import time
import random
import config
class DockerAPIClient:
def __new__(cls):
if not hasattr(cls, 'instance'):
cls.instance = super(DockerAPIClient, cls).__new__(cls)
cls.instance.init()
return cls.instance
def init(self):
self.client = docker.DockerClient(base_url=config.DOCKER_HOST_URL)
# Image pull
def pull_image(self, image):
print('pull_image: ', image)
self.client.images.pull(image)
def get_containers(self, is_all=False, filters={}):
return self.client.containers.list(all=is_all, filters=filters)
# コンテナ作成
def create_container(self, image, name=None, environment={}, volumes=[]):
print('create_container: ', name)
return self.client.containers.run(
image,
detach=True,
environment=environment,
name=name,
remove=True,
volumes=volumes,
)