Skip to content
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

#563 Adding functionality allowing custom hostnames in toolbox #1053

Closed
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
19 changes: 16 additions & 3 deletions src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
authFile string
container string
distro string
hostname string
image string
release string
}
Expand Down Expand Up @@ -85,6 +86,12 @@ func init() {
"",
"Create a toolbox container for a different operating system distribution than the host")

flags.StringVarP(&createFlags.hostname,
"hostname",
"h",
"toolbox",
"Assign a custom hostname to the toolbox container")

flags.StringVarP(&createFlags.image,
"image",
"i",
Expand Down Expand Up @@ -159,6 +166,12 @@ func create(cmd *cobra.Command, args []string) error {
}
}

var hostname string

if createFlags.hostname != "" {
hostname = createFlags.hostname
}

distro, err := utils.ResolveDistro(createFlags.distro)
if err != nil {
err := createErrorInvalidDistro()
Expand All @@ -185,14 +198,14 @@ func create(cmd *cobra.Command, args []string) error {
return err
}

if err := createContainer(container, image, release, true); err != nil {
if err := createContainer(container, hostname, image, release, true); err != nil {
return err
}

return nil
}

func createContainer(container, image, release string, showCommandToEnter bool) error {
func createContainer(container, hostname, image, release string, showCommandToEnter bool) error {
if container == "" {
panic("container not specified")
}
Expand Down Expand Up @@ -419,7 +432,7 @@ func createContainer(container, image, release string, showCommandToEnter bool)
createArgs = append(createArgs, xdgRuntimeDirEnv...)

createArgs = append(createArgs, []string{
"--hostname", "toolbox",
"--hostname", hostname,
"--ipc", "host",
"--label", "com.github.containers.toolbox=true",
}...)
Expand Down
8 changes: 7 additions & 1 deletion src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,13 @@ func runCommand(container string,
return nil
}

if err := createContainer(container, image, release, false); err != nil {
var hostname string

if createFlags.hostname != "" {
hostname = createFlags.hostname
}

if err := createContainer(container, hostname, image, release, false); err != nil {
return err
}
} else if containersCount == 1 && defaultContainer {
Expand Down