Skip to content
Open
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
2 changes: 2 additions & 0 deletions doc/toolbox-create.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ toolbox\-create - Create a new Toolbx container
[*--distro DISTRO* | *-d DISTRO*]
[*--image NAME* | *-i NAME*]
[*--release RELEASE* | *-r RELEASE*]
[*--volume* | *-V* [SOURCE-VOLUME|HOST-DIR:]CONTAINER-DIR[:OPTIONS]]
[*--env* | *-E* NAME[=VALUE]]
[*CONTAINER*]

## DESCRIPTION
Expand Down
36 changes: 29 additions & 7 deletions src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ const (

var (
createFlags struct {
authFile string
container string
distro string
image string
release string
authFile string
container string
distro string
image string
release string
extraVolumes []string
extraEnvVars []string
}

createToolboxShMounts = []struct {
Expand Down Expand Up @@ -104,6 +106,18 @@ func init() {
"",
"Create a Toolbx container for a different operating system release than the host")

flags.StringArrayVarP(&createFlags.extraVolumes,
"volume",
"V",
nil,
"Mount an additional volume in the toolbox container (may be repeated)")

flags.StringArrayVarP(&createFlags.extraEnvVars,
"env",
"E",
nil,
"Define an additional environment variable for the container (may be repeated)")

createCmd.SetHelpFunc(createHelp)

if err := createCmd.RegisterFlagCompletionFunc("distro", completionDistroNames); err != nil {
Expand Down Expand Up @@ -180,14 +194,14 @@ func create(cmd *cobra.Command, args []string) error {
return err
}

if err := createContainer(container, image, release, createFlags.authFile, true); err != nil {
if err := createContainer(container, image, release, createFlags.authFile, createFlags.extraVolumes, createFlags.extraEnvVars, true); err != nil {
return err
}

return nil
}

func createContainer(container, image, release, authFile string, showCommandToEnter bool) error {
func createContainer(container, image, release, authFile string, extraVolumes []string, extraEnvVars []string, showCommandToEnter bool) error {
if container == "" {
panic("container not specified")
}
Expand Down Expand Up @@ -473,6 +487,14 @@ func createContainer(container, image, release, authFile string, showCommandToEn
createArgs = append(createArgs, runMediaMount...)
createArgs = append(createArgs, toolboxShMount...)

for _, v := range extraVolumes {
createArgs = append(createArgs, "--volume", v)
}

for _, e := range extraEnvVars {
createArgs = append(createArgs, "--env", e)
}

createArgs = append(createArgs, []string{
imageFull,
}...)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func runCommand(container string,
return nil
}

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