Skip to content

Commit

Permalink
cmd/create, doc/toolbox-create, sh: Add flag --hostname to create com…
Browse files Browse the repository at this point in the history
…mand.

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
  • Loading branch information
likan999 committed Oct 30, 2020
1 parent b8b7245 commit 94fa8d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions doc/toolbox-create.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolbox\-create - Create a new toolbox container
## SYNOPSIS
**toolbox create** [*--candidate-registry*]
[*--container NAME* | *-c NAME*]
[*--hostname HOSTNAME*]
[*--image NAME* | *-i NAME*]
[*--release RELEASE* | *-r RELEASE*]

Expand Down Expand Up @@ -41,6 +42,10 @@ Assign a different NAME to the toolbox container. This is useful for creating
multiple toolbox containers from the same base image, or for entirely
customized containers from custom-built base images.

**--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
Expand Down
8 changes: 7 additions & 1 deletion src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
var (
createFlags struct {
container string
hostname string
image string
release string
}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -334,7 +340,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",
Expand Down
8 changes: 7 additions & 1 deletion toolbox
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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)
Expand Down Expand Up @@ -1074,7 +1075,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" \
Expand Down Expand Up @@ -2398,6 +2399,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"
Expand Down

0 comments on commit 94fa8d7

Please sign in to comment.