Skip to content

Commit

Permalink
When populating CMD, do not include Entrypoint
Browse files Browse the repository at this point in the history
Previously, we use CreateConfig's Command to populate container
Command (which is used as CMD for Inspect and Commit).
Unfortunately, CreateConfig's Command is the container's full
command, including a prepend of Entrypoint - so we duplicate
Entrypoint for images that include it.

Maintain a separate UserCommand in CreateConfig that does not
include the entrypoint, and use that instead.

Fixes containers#3708

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
  • Loading branch information
mheon committed Aug 6, 2019
1 parent f0a5b7f commit 838b211
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cmd/podman/shared/create.go
Expand Up @@ -588,6 +588,7 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
workDir = data.Config.WorkingDir
}

userCommand := []string{}
entrypoint := configureEntrypoint(c, data)
// Build the command
// If we have an entry point, it goes first
Expand All @@ -597,9 +598,11 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
if len(inputCommand) > 0 {
// User command overrides data CMD
command = append(command, inputCommand...)
userCommand = append(userCommand, inputCommand...)
} else if data != nil && len(data.Config.Cmd) > 0 && !c.IsSet("entrypoint") {
// If not user command, add CMD
command = append(command, data.Config.Cmd...)
userCommand = append(userCommand, data.Config.Cmd...)
}

if data != nil && len(command) == 0 {
Expand Down Expand Up @@ -680,6 +683,7 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
Cgroupns: c.String("cgroupns"),
CgroupParent: c.String("cgroup-parent"),
Command: command,
UserCommand: userCommand,
Detach: c.Bool("detach"),
Devices: c.StringSlice("device"),
DNSOpt: c.StringSlice("dns-opt"),
Expand Down
7 changes: 4 additions & 3 deletions pkg/spec/createconfig.go
Expand Up @@ -65,7 +65,8 @@ type CreateConfig struct {
ConmonPidFile string
Cgroupns string
CgroupParent string // cgroup-parent
Command []string
Command []string // Full command that will be used
UserCommand []string // User-entered command (or image CMD)
Detach bool // detach
Devices []string // device
DNSOpt []string //dns-opt
Expand Down Expand Up @@ -230,8 +231,8 @@ func (c *CreateConfig) getContainerCreateOptions(runtime *libpod.Runtime, pod *l
options = append(options, libpod.WithNamedVolumes(namedVolumes))
}

if len(c.Command) != 0 {
options = append(options, libpod.WithCommand(c.Command))
if len(c.UserCommand) != 0 {
options = append(options, libpod.WithCommand(c.UserCommand))
}

// Add entrypoint unconditionally
Expand Down

0 comments on commit 838b211

Please sign in to comment.