Skip to content

cmd/create, doc/toolbox-create, sh: Add flag --hostname to create command. #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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** [*--container NAME* | *-c NAME*]
[*--distro DISTRO* | *-d DISTRO*]
[*--hostname HOSTNAME*]
[*--image NAME* | *-i NAME*]
[*--release RELEASE* | *-r RELEASE*]

Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
createFlags struct {
container string
distro string
hostname string
image string
release string
}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't directly use createFlags.hostname in createContainer because src/cmd/run.go also uses this function.

"--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 @@ -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)
Expand Down Expand Up @@ -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" \
Expand Down Expand Up @@ -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"
Expand Down