Skip to content

Commit 6f5ab38

Browse files
committed
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. #573
1 parent 69dd701 commit 6f5ab38

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

doc/toolbox-create.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ toolbox\-create - Create a new toolbox container
66
## SYNOPSIS
77
**toolbox create** [*--container NAME* | *-c NAME*]
88
[*--distro DISTRO* | *-d DISTRO*]
9+
[*--hostname HOSTNAME*]
910
[*--image NAME* | *-i NAME*]
1011
[*--release RELEASE* | *-r RELEASE*]
1112

@@ -41,6 +42,10 @@ customized containers from custom-built base images.
4142
Create a toolbox container for a different operating system DISTRO than the
4243
host. Cannot be used with `--image`.
4344

45+
**--hostname** HOSTNAME
46+
47+
Create the toolbox container using the specified hostname (default: toolbox).
48+
4449
**--image** NAME, **-i** NAME
4550

4651
Change the NAME of the base image used to create the toolbox container. This

src/cmd/create.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var (
4444
createFlags struct {
4545
container string
4646
distro string
47+
hostname string
4748
image string
4849
release string
4950
}
@@ -78,6 +79,11 @@ func init() {
7879
"",
7980
"Create a toolbox container for a different operating system distribution than the host")
8081

82+
flags.StringVar(&createFlags.hostname,
83+
"hostname",
84+
"toolbox",
85+
"Create the toolbox container using the specified hostname (default: toolbox).")
86+
8187
flags.StringVarP(&createFlags.image,
8288
"image",
8389
"i",
@@ -390,7 +396,7 @@ func createContainer(container, image, release string, showCommandToEnter bool)
390396
createArgs = append(createArgs, xdgRuntimeDirEnv...)
391397

392398
createArgs = append(createArgs, []string{
393-
"--hostname", "toolbox",
399+
"--hostname", createFlags.hostname,
394400
"--ipc", "host",
395401
"--label", "com.github.containers.toolbox=true",
396402
"--label", "com.github.debarshiray.toolbox=true",

toolbox

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ toolbox_container_default=""
7070
toolbox_container_old_v1=""
7171
toolbox_container_old_v2=""
7272
toolbox_container_prefix_default=""
73+
toolbox_hostname=toolbox
7374
toolbox_image=""
7475
toolbox_runtime_directory="$XDG_RUNTIME_DIR"/toolbox
7576
user_id_real=$(id -ru 2>&3)
@@ -1075,7 +1076,7 @@ create()
10751076
$podman_command create \
10761077
--dns none \
10771078
--env TOOLBOX_PATH="$TOOLBOX_PATH" \
1078-
--hostname toolbox \
1079+
--hostname "${toolbox_hostname}" \
10791080
--ipc host \
10801081
--label "com.github.containers.toolbox=true" \
10811082
--label "com.github.debarshiray.toolbox=true" \
@@ -2399,6 +2400,11 @@ case $op in
23992400
help "$op"
24002401
exit
24012402
;;
2403+
--hostname )
2404+
shift
2405+
exit_if_missing_argument --hostname "$1"
2406+
toolbox_hostname=$1
2407+
;;
24022408
-i | --image )
24032409
shift
24042410
exit_if_missing_argument --image "$1"

0 commit comments

Comments
 (0)