From c68d73e6720a7df2b48df17ac7b9b4c906e0294c Mon Sep 17 00:00:00 2001 From: Viacheslav Hletenko Date: Tue, 28 Feb 2023 14:25:39 +0000 Subject: T4967: Allow setting container hostname Ability setting container hostname This host name is used as /etc/hostname set container name host-name 'mybox' --- interface-definitions/container.xml.in | 9 +++++++++ src/conf_mode/container.py | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/interface-definitions/container.xml.in b/interface-definitions/container.xml.in index 2ea1e6ab2..0e5fdea78 100644 --- a/interface-definitions/container.xml.in +++ b/interface-definitions/container.xml.in @@ -113,6 +113,15 @@ Entrypoint must be ascii characters, use " and &apos for double and single quotes respectively + + + Container host name + + [A-Za-z0-9][-.A-Za-z0-9]*[A-Za-z0-9] + + Host-name must be alphanumeric and can contain hyphens + + Image name in the hub-registry diff --git a/src/conf_mode/container.py b/src/conf_mode/container.py index 4f93c93a1..10e9e9213 100755 --- a/src/conf_mode/container.py +++ b/src/conf_mode/container.py @@ -256,6 +256,11 @@ def generate_run_arguments(name, container_config): for k, v in container_config['environment'].items(): env_opt += f" --env \"{k}={v['value']}\"" + hostname = '' + if 'host_name' in container_config: + hostname = container_config['host_name'] + hostname = f'--hostname {hostname}' + # Publish ports port = '' if 'port' in container_config: @@ -277,7 +282,7 @@ def generate_run_arguments(name, container_config): container_base_cmd = f'--detach --interactive --tty --replace {cap_add} ' \ f'--memory {memory}m --shm-size {shared_memory}m --memory-swap 0 --restart {restart} ' \ - f'--name {name} {device} {port} {volume} {env_opt}' + f'--name {name} {hostname} {device} {port} {volume} {env_opt}' entrypoint = '' if 'entrypoint' in container_config: @@ -285,6 +290,11 @@ def generate_run_arguments(name, container_config): entrypoint = json_write(container_config['entrypoint'].split()).replace('"', """) entrypoint = f'--entrypoint '{entrypoint}'' + hostname = '' + if 'host_name' in container_config: + hostname = container_config['host_name'] + hostname = f'--hostname {hostname}' + command = '' if 'command' in container_config: command = container_config['command'].strip() -- cgit v1.2.3