mirror of
https://github.com/containers/podman.git
synced 2025-06-25 03:52:15 +08:00
Do not use image CMD if user gave ENTRYPOINT
This matches Docker behavior, and seems to make sense - the CMD may have been specific to the original entrypoint and probably does not make sense if it was changed. While we're in here, greatly simplify the logic for populating the SpecGen's Command. We create the full command when making the OCI spec, so the client should not be doing any more than setting it to the Command the user passed in, and completely ignoring ENTRYPOINT. Fixes #7115 Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:

committed by
Matthew Heon

parent
da00482ef2
commit
39c493b3fc
@ -387,8 +387,6 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
|
|||||||
s.Annotations = annotations
|
s.Annotations = annotations
|
||||||
|
|
||||||
s.WorkDir = c.Workdir
|
s.WorkDir = c.Workdir
|
||||||
userCommand := []string{}
|
|
||||||
var command []string
|
|
||||||
if c.Entrypoint != nil {
|
if c.Entrypoint != nil {
|
||||||
entrypoint := []string{}
|
entrypoint := []string{}
|
||||||
if ep := *c.Entrypoint; len(ep) > 0 {
|
if ep := *c.Entrypoint; len(ep) > 0 {
|
||||||
@ -398,27 +396,13 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.Entrypoint = entrypoint
|
s.Entrypoint = entrypoint
|
||||||
// Build the command
|
|
||||||
// If we have an entry point, it goes first
|
|
||||||
command = entrypoint
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include the command used to create the container.
|
// Include the command used to create the container.
|
||||||
s.ContainerCreateCommand = os.Args
|
s.ContainerCreateCommand = os.Args
|
||||||
|
|
||||||
if len(inputCommand) > 0 {
|
if len(inputCommand) > 0 {
|
||||||
// User command overrides data CMD
|
s.Command = inputCommand
|
||||||
command = append(command, inputCommand...)
|
|
||||||
userCommand = append(userCommand, inputCommand...)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case len(inputCommand) > 0:
|
|
||||||
s.Command = userCommand
|
|
||||||
case c.Entrypoint != nil:
|
|
||||||
s.Command = []string{}
|
|
||||||
default:
|
|
||||||
s.Command = command
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SHM Size
|
// SHM Size
|
||||||
|
@ -96,8 +96,10 @@ func makeCommand(ctx context.Context, s *specgen.SpecGenerator, img *image.Image
|
|||||||
|
|
||||||
finalCommand = append(finalCommand, entrypoint...)
|
finalCommand = append(finalCommand, entrypoint...)
|
||||||
|
|
||||||
|
// Only use image command if the user did not manually set an
|
||||||
|
// entrypoint.
|
||||||
command := s.Command
|
command := s.Command
|
||||||
if command == nil && img != nil {
|
if command == nil && img != nil && s.Entrypoint == nil {
|
||||||
newCmd, err := img.Cmd(ctx)
|
newCmd, err := img.Cmd(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1143,7 +1143,7 @@ USER mail`
|
|||||||
Expect(session.ErrorToString()).To(ContainSubstring("Invalid umask"))
|
Expect(session.ErrorToString()).To(ContainSubstring("Invalid umask"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman run makes entrypoint from image", func() {
|
It("podman run makes workdir from image", func() {
|
||||||
// BuildImage does not seem to work remote
|
// BuildImage does not seem to work remote
|
||||||
SkipIfRemote()
|
SkipIfRemote()
|
||||||
dockerfile := `FROM busybox
|
dockerfile := `FROM busybox
|
||||||
@ -1154,4 +1154,13 @@ WORKDIR /madethis`
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("/madethis"))
|
Expect(session.OutputToString()).To(ContainSubstring("/madethis"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman run --entrypoint does not use image command", func() {
|
||||||
|
session := podmanTest.Podman([]string{"run", "--entrypoint", "/bin/echo", ALPINE})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
// We can't guarantee the output is completely empty, some
|
||||||
|
// nonprintables seem to work their way in.
|
||||||
|
Expect(session.OutputToString()).To(Not(ContainSubstring("/bin/sh")))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user