Extend DockerContainerRun with some useful parameters
This commit is contained in:
parent
5c716db2b6
commit
81fcc339d3
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user