Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ class ContainerConfiguration:
volumes: VolumeMappings = dataclasses.field(default_factory=VolumeMappings)
ports: PortMappings = dataclasses.field(default_factory=PortMappings)
exposed_ports: List[str] = dataclasses.field(default_factory=list)
entrypoint: Optional[str] = None
entrypoint: Optional[Union[List[str], str]] = None
additional_flags: Optional[str] = None
command: Optional[List[str]] = None
env_vars: Dict[str, str] = dataclasses.field(default_factory=dict)
Expand Down Expand Up @@ -861,7 +861,7 @@ def create_container(
image_name: str,
*,
name: Optional[str] = None,
entrypoint: Optional[str] = None,
entrypoint: Optional[Union[List[str], str]] = None,
remove: bool = False,
interactive: bool = False,
tty: bool = False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def _build_run_create_cmd(
image_name: str,
*,
name: Optional[str] = None,
entrypoint: Optional[str] = None,
entrypoint: Optional[Union[List[str], str]] = None,
remove: bool = False,
interactive: bool = False,
tty: bool = False,
Expand Down Expand Up @@ -746,7 +746,10 @@ def _build_run_create_cmd(
if name:
cmd += ["--name", name]
if entrypoint is not None: # empty string entrypoint can be intentional
cmd += ["--entrypoint", entrypoint]
if isinstance(entrypoint, str):
cmd += ["--entrypoint", entrypoint]
else:
cmd += ["--entrypoint", shlex.join(entrypoint)]
if privileged:
cmd += ["--privileged"]
if volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def create_container(
image_name: str,
*,
name: Optional[str] = None,
entrypoint: Optional[str] = None,
entrypoint: Optional[Union[List[str], str]] = None,
remove: bool = False,
interactive: bool = False,
tty: bool = False,
Expand Down
26 changes: 24 additions & 2 deletions tests/integration/docker_utils/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import textwrap
import time
from typing import NamedTuple, Type
from typing import Callable, NamedTuple, Type

import pytest
from docker.models.containers import Container
Expand Down Expand Up @@ -85,7 +85,7 @@ def create_container(docker_client: ContainerClient, create_network):
"""
containers = []

def _create_container(image_name: str, **kwargs):
def _create_container(image_name: str, **kwargs) -> ContainerInfo:
kwargs["name"] = kwargs.get("name", _random_container_name())
cid = docker_client.create_container(image_name, **kwargs)
cid = cid.strip()
Expand Down Expand Up @@ -187,6 +187,28 @@ def test_create_container_remove_removes_container(
# it takes a while for it to be removed
assert "foobar" in output

@pytest.mark.parametrize(
"entrypoint",
[
"echo",
["echo"],
],
)
def test_set_container_entrypoint(
self,
docker_client: ContainerClient,
create_container: Callable[..., ContainerInfo],
entrypoint: list[str] | str,
):
info = create_container("alpine", entrypoint=entrypoint, command=["true"])
assert 1 == len(docker_client.list_containers(f"id={info.container_id}"))

# start the container
output, _ = docker_client.start_container(info.container_id, attach=True)
output = to_str(output).strip()

assert output == "true"

@markers.skip_offline
def test_create_container_non_existing_image(self, docker_client: ContainerClient):
with pytest.raises(NoSuchImage):
Expand Down
Loading