From 81fcc339d34a36f8116aeb11de56f94120e4ca55 Mon Sep 17 00:00:00 2001 From: Olivier Date: Thu, 31 Dec 2020 20:59:22 +0000 Subject: [PATCH] Extend DockerContainerRun with some useful parameters --- scone/default/utensils/docker_utensils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scone/default/utensils/docker_utensils.py b/scone/default/utensils/docker_utensils.py index 7ce9760..fc69820 100644 --- a/scone/default/utensils/docker_utensils.py +++ b/scone/default/utensils/docker_utensils.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import Optional +from typing import Optional, Tuple, Dict import attr @@ -70,7 +70,14 @@ class DockerContainerRun(Utensil): # Command to create the container with. command: str # Custom name to give the container. - name: Optional[str] = None + name: str + # Ports to bind inside the container + # {'2222/tcp': ('127.0.0.1', 3333)} will expose port 2222 inside as 3333 outside. + ports: Dict[str, Tuple[str, int]] + # Volumes to mount inside the container. + # Key is either a host path or a container name. + # Value is a dictionary with the keys. + volumes: Dict[str, Dict[str, str]] @attr.s(auto_attribs=True) class Result: @@ -79,7 +86,8 @@ class DockerContainerRun(Utensil): async def execute(self, channel: Channel, worktop: Worktop): try: container = _docker_client().containers.run( - self.image, self.command, detach=True + self.image, self.command, detach=True, + name=self.name, ports=self.ports, volumes=self.volumes ) except docker.errors.ImageNotFound: