Skip to content

Commit dae2430

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. containers#573
1 parent 09d2c46 commit dae2430

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** [*--candidate-registry*]
88
[*--container NAME* | *-c NAME*]
9+
[*--hostname HOSTNAME*]
910
[*--image NAME* | *-i NAME*]
1011
[*--release RELEASE* | *-r RELEASE*]
1112

@@ -41,6 +42,10 @@ Assign a different NAME to the toolbox container. This is useful for creating
4142
multiple toolbox containers from the same base image, or for entirely
4243
customized containers from custom-built base images.
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
@@ -43,6 +43,7 @@ const (
4343
var (
4444
createFlags struct {
4545
container string
46+
hostname string
4647
image string
4748
release string
4849
}
@@ -71,6 +72,11 @@ func init() {
7172
"",
7273
"Assign a different name to the toolbox container.")
7374

75+
flags.StringVar(&createFlags.hostname,
76+
"hostname",
77+
"toolbox",
78+
"Create the toolbox container using the specified hostname (default: toolbox).")
79+
7480
flags.StringVarP(&createFlags.image,
7581
"image",
7682
"i",
@@ -363,7 +369,7 @@ func createContainer(container, image, release string, showCommandToEnter bool)
363369
createArgs = append(createArgs, xdgRuntimeDirEnv...)
364370

365371
createArgs = append(createArgs, []string{
366-
"--hostname", "toolbox",
372+
"--hostname", createFlags.hostname,
367373
"--ipc", "host",
368374
"--label", "com.github.containers.toolbox=true",
369375
"--label", "com.github.debarshiray.toolbox=true",

toolbox

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ toolbox_container_default=""
6969
toolbox_container_old_v1=""
7070
toolbox_container_old_v2=""
7171
toolbox_container_prefix_default=""
72+
toolbox_hostname=toolbox
7273
toolbox_image=""
7374
toolbox_runtime_directory="$XDG_RUNTIME_DIR"/toolbox
7475
user_id_real=$(id -ru 2>&3)
@@ -1074,7 +1075,7 @@ create()
10741075
$podman_command create \
10751076
--dns none \
10761077
--env TOOLBOX_PATH="$TOOLBOX_PATH" \
1077-
--hostname toolbox \
1078+
--hostname "${toolbox_hostname}" \
10781079
--ipc host \
10791080
--label "com.github.containers.toolbox=true" \
10801081
--label "com.github.debarshiray.toolbox=true" \
@@ -2398,6 +2399,11 @@ case $op in
23982399
help "$op"
23992400
exit
24002401
;;
2402+
--hostname )
2403+
shift
2404+
exit_if_missing_argument --hostname "$1"
2405+
toolbox_hostname=$1
2406+
;;
24012407
-i | --image )
24022408
shift
24032409
exit_if_missing_argument --image "$1"

0 commit comments

Comments
 (0)