-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_container.py
More file actions
27 lines (23 loc) · 1005 Bytes
/
run_container.py
File metadata and controls
27 lines (23 loc) · 1005 Bytes
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
import docker
def run_container(image_name, container_name, requirements_file):
client = docker.from_env()
try:
# Считываем содержимое файла requirements.txt
with open(requirements_file, 'r') as file:
requirements = file.read().splitlines()
# Строим контейнер
container = client.containers.run(
image=image_name,
name=container_name,
detach=True,
volumes={requirements_file: {'bind': '/requirements.txt', 'mode': 'ro'}},
command=f"sh -c 'pip install -r /requirements.txt && tail -f /dev/null'"
)
print(f"Container {container_name} started successfully.")
except docker.errors.APIError as e:
print(f"Error starting container: {e}")
if __name__ == "__main__":
image_name = "python"
container_name = "droner"
requirements_file = "requirements.txt"
run_container(image_name, container_name, requirements_file)