When populating CMD, do not include Entrypoint

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 #3708

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
Matthew Heon 2019-08-06 15:55:33 -04:00
parent f0a5b7ff99
commit 28b545d04c
2 changed files with 9 additions and 4 deletions

View File

@ -588,6 +588,7 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
workDir = data.Config.WorkingDir workDir = data.Config.WorkingDir
} }
userCommand := []string{}
entrypoint := configureEntrypoint(c, data) entrypoint := configureEntrypoint(c, data)
// Build the command // Build the command
// If we have an entry point, it goes first // If we have an entry point, it goes first
@ -597,9 +598,11 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
if len(inputCommand) > 0 { if len(inputCommand) > 0 {
// User command overrides data CMD // User command overrides data CMD
command = append(command, inputCommand...) command = append(command, inputCommand...)
userCommand = append(userCommand, inputCommand...)
} else if data != nil && len(data.Config.Cmd) > 0 && !c.IsSet("entrypoint") { } else if data != nil && len(data.Config.Cmd) > 0 && !c.IsSet("entrypoint") {
// If not user command, add CMD // If not user command, add CMD
command = append(command, data.Config.Cmd...) command = append(command, data.Config.Cmd...)
userCommand = append(userCommand, data.Config.Cmd...)
} }
if data != nil && len(command) == 0 { if data != nil && len(command) == 0 {
@ -680,6 +683,7 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
Cgroupns: c.String("cgroupns"), Cgroupns: c.String("cgroupns"),
CgroupParent: c.String("cgroup-parent"), CgroupParent: c.String("cgroup-parent"),
Command: command, Command: command,
UserCommand: userCommand,
Detach: c.Bool("detach"), Detach: c.Bool("detach"),
Devices: c.StringSlice("device"), Devices: c.StringSlice("device"),
DNSOpt: c.StringSlice("dns-opt"), DNSOpt: c.StringSlice("dns-opt"),

View File

@ -64,8 +64,9 @@ type CreateConfig struct {
CidFile string CidFile string
ConmonPidFile string ConmonPidFile string
Cgroupns string Cgroupns string
CgroupParent string // cgroup-parent 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 Detach bool // detach
Devices []string // device Devices []string // device
DNSOpt []string //dns-opt DNSOpt []string //dns-opt
@ -230,8 +231,8 @@ func (c *CreateConfig) getContainerCreateOptions(runtime *libpod.Runtime, pod *l
options = append(options, libpod.WithNamedVolumes(namedVolumes)) options = append(options, libpod.WithNamedVolumes(namedVolumes))
} }
if len(c.Command) != 0 { if len(c.UserCommand) != 0 {
options = append(options, libpod.WithCommand(c.Command)) options = append(options, libpod.WithCommand(c.UserCommand))
} }
// Add entrypoint unconditionally // Add entrypoint unconditionally