Skip to content

Commit 3e34992

Browse files
authored
Merge pull request #20953 from natefoo/docker-host-port-cmd
Allow specifying a command for determining a docker host port
2 parents 5470309 + e667761 commit 3e34992

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lib/galaxy/config/sample/job_conf.sample.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ execution:
524524
# Following command can be used to tweak docker command.
525525
#docker_cmd: /usr/local/custom_docker/docker
526526

527+
# Docker containers that expose ports (e.g. Interactive Tools) can
528+
# optionally use a command to determine the host port that is exposed. By
529+
# default, one is chosen at random (docker run -p <guest_port> ...).
530+
#docker_host_port_cmd:
531+
527532
# Following can be used to connect to docker server in different
528533
# ways (translated as -H argument to docker client).
529534
#docker_host: unix:///var/run/docker.sock

lib/galaxy/tool_util/deps/container_classes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ def containerize_command(self, command: str) -> str:
481481
set_user=self.prop("set_user", docker_util.DEFAULT_SET_USER),
482482
run_extra_arguments=self.prop("run_extra_arguments", docker_util.DEFAULT_RUN_EXTRA_ARGUMENTS),
483483
guest_ports=self.tool_info.guest_ports,
484+
host_port_cmd=self.prop("host_port_cmd", None),
484485
container_name=self.container_name,
485486
**docker_host_props,
486487
)

lib/galaxy/tool_util/deps/docker_util.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def build_docker_run_command(
111111
set_user: Optional[str] = DEFAULT_SET_USER,
112112
host: Optional[str] = DEFAULT_HOST,
113113
guest_ports: Union[bool, str, List[str]] = False,
114+
host_port_cmd: Optional[str] = None,
114115
container_name: Optional[str] = None,
115116
) -> str:
116117
env_directives = env_directives or []
@@ -129,10 +130,14 @@ def build_docker_run_command(
129130
# When is True, expose all ports
130131
command_parts.append("-P")
131132
elif guest_ports:
133+
if host_port_cmd:
134+
host_port_cmd = f"$({host_port_cmd}):"
135+
else:
136+
host_port_cmd = ""
132137
if not isinstance(guest_ports, list):
133138
guest_ports = [guest_ports]
134139
for guest_port in guest_ports:
135-
command_parts.extend(["-p", guest_port])
140+
command_parts.extend(["-p", f"{host_port_cmd}{guest_port}"])
136141
if container_name:
137142
command_parts.extend(["--name", container_name])
138143
for volume in volumes:

0 commit comments

Comments
 (0)