mirror of
https://github.com/newnius/YAO-agent.git
synced 2025-06-06 21:31:55 +00:00
update, support network alias
This commit is contained in:
parent
f1ec22bc8e
commit
84dac98ccc
32
executor.py
32
executor.py
@ -83,23 +83,35 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||
docker_workspace = form.getvalue('workspace')
|
||||
docker_gpus = form.getvalue('gpus')
|
||||
docker_mem_limit = form.getvalue('mem_limit')
|
||||
docker_cpu_limit = form.getvalue('cpu_limit')
|
||||
docker_cpu_limit = int(form.getvalue('cpu_limit'))
|
||||
docker_network = form.getvalue('network')
|
||||
|
||||
try:
|
||||
client = docker.from_env()
|
||||
container = client.containers.run(
|
||||
name=docker_name,
|
||||
hostname=docker_name,
|
||||
client = docker.APIClient(base_url='unix://var/run/docker.sock')
|
||||
|
||||
host_config = client.create_host_config(
|
||||
mem_limit=docker_mem_limit,
|
||||
cpu_shares=docker_cpu_limit * 1024
|
||||
)
|
||||
networking_config = client.create_networking_config(
|
||||
endpoints_config={
|
||||
docker_network: client.create_endpoint_config(
|
||||
aliases=[docker_name],
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
container = client.create_container(
|
||||
image=docker_image,
|
||||
command=docker_cmd,
|
||||
mem_limit=docker_mem_limit,
|
||||
nano_cpus=docker_cpu_limit,
|
||||
network=docker_network,
|
||||
hostname=docker_name,
|
||||
detach=True,
|
||||
host_config=host_config,
|
||||
environment={"repo": docker_workspace, "NVIDIA_VISIBLE_DEVICES": docker_gpus},
|
||||
runtime="nvidia",
|
||||
detach=True
|
||||
networking_config=networking_config,
|
||||
runtime='nvidia'
|
||||
)
|
||||
client.start(container)
|
||||
msg = {"code": 0, "id": container.id}
|
||||
except Exception as e:
|
||||
msg = {"code": 1, "error": str(e)}
|
||||
|
34
test.py
34
test.py
@ -69,8 +69,36 @@ def remove_network():
|
||||
client.networks.prune(filters={'name': 'yao-net-1024'})
|
||||
|
||||
|
||||
#create_network()
|
||||
#list_networks()
|
||||
def create_container():
|
||||
client = docker.APIClient(base_url='unix://var/run/docker.sock')
|
||||
|
||||
#remove_network()
|
||||
host_config = client.create_host_config(
|
||||
mem_limit='512m',
|
||||
cpu_shares=1 * 1024
|
||||
)
|
||||
networking_config = client.create_networking_config(
|
||||
endpoints_config={
|
||||
'yao-net-1201': client.create_endpoint_config(
|
||||
aliases=['node1'],
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
container = client.create_container(
|
||||
image='alpine',
|
||||
command='pwd',
|
||||
hostname='node1',
|
||||
detach=True,
|
||||
host_config=host_config,
|
||||
environment = {"repo": docker_workspace, "NVIDIA_VISIBLE_DEVICES": docker_gpus},
|
||||
networking_config=networking_config,
|
||||
runtime='nvidia'
|
||||
)
|
||||
client.start(container)
|
||||
|
||||
|
||||
# create_network()
|
||||
# list_networks()
|
||||
|
||||
# remove_network()
|
||||
get_status('af121babda9b')
|
||||
|
Loading…
Reference in New Issue
Block a user