Skip to content

Commit

Permalink
Add volumes option to docker.compose.run() (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
www84 committed Dec 25, 2024
1 parent 86804ee commit 887ba10
Show file tree
Hide file tree
Showing 2 changed files with 1,240 additions and 1,190 deletions.
10 changes: 9 additions & 1 deletion python_on_whales/components/compose/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing_extensions import Literal

import python_on_whales.components.container.cli_wrapper
import python_on_whales.components.volume.cli_wrapper
from python_on_whales.client_config import DockerCLICaller
from python_on_whales.components.compose.models import ComposeConfig, ComposeProject
from python_on_whales.utils import (
Expand Down Expand Up @@ -677,7 +678,9 @@ def run(
service_ports: bool = False,
use_aliases: bool = False,
user: Optional[str] = None,
# volumes: bool = "todo",
volumes: Iterable[
python_on_whales.components.volume.cli_wrapper.VolumeDefinition
] = (),
workdir: Union[None, str, Path] = None,
) -> Union[
str,
Expand All @@ -703,6 +706,8 @@ def run(
to write on it.
stream: Similar to `docker.run(..., stream=True)`.
user: Username or UID, format: `"<name|uid>[:<group|gid>]"`
volumes: Bind mount a volume. Some examples:
`[("/", "/host"), ("/etc/hosts", "/etc/hosts", "rw")]`.
workdir: Working directory inside the container
Returns:
Expand Down Expand Up @@ -746,6 +751,9 @@ def run(
full_cmd.add_flag("--service-ports", service_ports)
full_cmd.add_flag("--use-aliases", use_aliases)
full_cmd.add_simple_arg("--user", user)
for volume_definition in volumes:
volume_definition = tuple(str(x) for x in volume_definition)
full_cmd += ["--volume", ":".join(volume_definition)]
full_cmd.add_simple_arg("--workdir", workdir)
full_cmd.add_args_iterable_or_single("--label", format_mapping_for_cli(labels))
full_cmd.append(service)
Expand Down
Loading

0 comments on commit 887ba10

Please sign in to comment.