From 6f5ab388896874338781fe1356f34a20ea67f849 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 3ce3358dd..206beaa45 100644 --- a/doc/toolbox-create.1.md +++ b/doc/toolbox-create.1.md @@ -6,6 +6,7 @@ toolbox\-create - Create a new toolbox container ## SYNOPSIS **toolbox create** [*--container NAME* | *-c NAME*] [*--distro DISTRO* | *-d DISTRO*] + [*--hostname HOSTNAME*] [*--image NAME* | *-i NAME*] [*--release RELEASE* | *-r RELEASE*] @@ -41,6 +42,10 @@ customized containers from custom-built base images. Create a toolbox container for a different operating system DISTRO than the host. Cannot be used with `--image`. +**--hostname** HOSTNAME + +Create the toolbox container using the specified hostname (default: toolbox). + **--image** NAME, **-i** NAME Change the NAME of the base image used to create the toolbox container. This diff --git a/src/cmd/create.go b/src/cmd/create.go index 74e90b1b1..92766ad37 100644 --- a/src/cmd/create.go +++ b/src/cmd/create.go @@ -44,6 +44,7 @@ var ( createFlags struct { container string distro string + hostname string image string release string } @@ -78,6 +79,11 @@ func init() { "", "Create a toolbox container for a different operating system distribution than the host") + flags.StringVar(&createFlags.hostname, + "hostname", + "toolbox", + "Create the toolbox container using the specified hostname (default: toolbox).") + flags.StringVarP(&createFlags.image, "image", "i", @@ -390,7 +396,7 @@ func createContainer(container, image, release string, showCommandToEnter bool) createArgs = append(createArgs, xdgRuntimeDirEnv...) createArgs = append(createArgs, []string{ - "--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 c6ae396f4..44fee86a3 100755 --- a/toolbox +++ b/toolbox @@ -70,6 +70,7 @@ toolbox_container_default="" toolbox_container_old_v1="" toolbox_container_old_v2="" toolbox_container_prefix_default="" +toolbox_hostname=toolbox toolbox_image="" toolbox_runtime_directory="$XDG_RUNTIME_DIR"/toolbox user_id_real=$(id -ru 2>&3) @@ -1075,7 +1076,7 @@ create() $podman_command create \ --dns none \ --env TOOLBOX_PATH="$TOOLBOX_PATH" \ - --hostname toolbox \ + --hostname "${toolbox_hostname}" \ --ipc host \ --label "com.github.containers.toolbox=true" \ --label "com.github.debarshiray.toolbox=true" \ @@ -2399,6 +2400,11 @@ case $op in help "$op" exit ;; + --hostname ) + shift + exit_if_missing_argument --hostname "$1" + toolbox_hostname=$1 + ;; -i | --image ) shift exit_if_missing_argument --image "$1"