From cce0a35687041bf036d2e9475e586cef1437f13d Mon Sep 17 00:00:00 2001 From: Kan Li Date: Thu, 29 Oct 2020 18:26:32 -0700 Subject: [PATCH] cmd/create, doc/toolbox-create, sh: Add flag --hostname to create command. When SSH to a host, ~/.Xauthority will be used for xauth; the entries in it contains the hostname. If within the toolbox container it uses another hostname, the xauth will fail. Therefore we need to be able to specify the hostname when creating the container. https://github.com/containers/toolbox/pull/573 --- doc/toolbox-create.1.md | 5 +++++ src/cmd/create.go | 8 +++++++- toolbox | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/doc/toolbox-create.1.md b/doc/toolbox-create.1.md index ef53802a6..3257d7374 100644 --- a/doc/toolbox-create.1.md +++ b/doc/toolbox-create.1.md @@ -8,6 +8,7 @@ toolbox\-create - Create a new toolbox container [*--container NAME* | *-c NAME*] [*--image NAME* | *-i NAME*] [*--release RELEASE* | *-r RELEASE*] + [*--hostname HOSTNAME*] ## DESCRIPTION @@ -51,6 +52,10 @@ is useful for creating containers from custom-built base images. Create a toolbox container for a different operating system RELEASE than the host. +**--hostname** HOSTNAME + +Create the toolbox container using the specified hostname (default: toolbox). + ## EXAMPLES ### Create a toolbox container using the default image matching the host OS diff --git a/src/cmd/create.go b/src/cmd/create.go index 9acc61258..f21746f10 100644 --- a/src/cmd/create.go +++ b/src/cmd/create.go @@ -43,6 +43,7 @@ const ( var ( createFlags struct { container string + hostname string image string release string } @@ -71,6 +72,11 @@ func init() { "", "Assign a different name to the toolbox container.") + flags.StringVar(&createFlags.hostname, + "hostname", + "toolbox", + "Create the toolbox container using the specified hostname (default: toolbox).") + flags.StringVarP(&createFlags.image, "image", "i", @@ -336,7 +342,7 @@ func createContainer(container, image, release string, showCommandToEnter bool) "create", "--dns", "none", "--env", toolboxPathEnvArg, - "--hostname", "toolbox", + "--hostname", createFlags.hostname, "--ipc", "host", "--label", "com.github.containers.toolbox=true", "--label", "com.github.debarshiray.toolbox=true", diff --git a/toolbox b/toolbox index 8a8c16727..615bff72d 100755 --- a/toolbox +++ b/toolbox @@ -72,6 +72,7 @@ toolbox_container_prefix_default="" toolbox_image="" toolbox_runtime_directory="$XDG_RUNTIME_DIR"/toolbox user_id_real=$(id -ru 2>&3) +hostname=toolbox verbose=false @@ -1074,7 +1075,7 @@ create() $podman_command create \ --dns none \ --env TOOLBOX_PATH="$TOOLBOX_PATH" \ - --hostname toolbox \ + --hostname "${hostname}" \ --ipc host \ --label "com.github.containers.toolbox=true" \ --label "com.github.debarshiray.toolbox=true" \ @@ -2398,6 +2399,11 @@ case $op in help "$op" exit ;; + --hostname ) + shift + exit_if_missing_argument --hostname "$1" + hostname=$1 + ;; -i | --image ) shift exit_if_missing_argument --image "$1"