Coverage for src/container_collection/docker/run_docker_command.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2024-09-25 18:23 +0000

1from __future__ import annotations 

2 

3from typing import TYPE_CHECKING 

4 

5if TYPE_CHECKING: 

6 from docker import DockerClient 

7 

8 

9def run_docker_command( 

10 client: DockerClient, 

11 image: str, 

12 command: list[str], 

13 volume: str | None = None, 

14 environment: list | None = None, 

15 *, 

16 detach: bool, 

17) -> None: 

18 """ 

19 Run container from image with given command. 

20 

21 Parameters 

22 ---------- 

23 client 

24 Docker API client. 

25 image 

26 Docker image. 

27 command 

28 Command list passed to container. 

29 volume 

30 Name of the docker volume. 

31 environment 

32 List of environment variables as strings. 

33 detach 

34 True to start container and immediately return the Container object, 

35 False otherwise. 

36 """ 

37 

38 environment = [] if environment is None else environment 

39 volumes = {} if volume is None else {volume: {"bind": "/mnt", "mode": "rw"}} 

40 

41 client.containers.run( 

42 image, 

43 command, 

44 environment=environment, 

45 volumes=volumes, 

46 auto_remove=True, 

47 detach=detach, 

48 )