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

Do not use image CMD if user gave ENTRYPOINT #7256

Merged
Merged
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
18 changes: 1 addition & 17 deletions cmd/podman/common/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,6 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
s.Annotations = annotations

s.WorkDir = c.Workdir
userCommand := []string{}
var command []string
if c.Entrypoint != nil {
entrypoint := []string{}
if ep := *c.Entrypoint; len(ep) > 0 {
Expand All @@ -398,27 +396,13 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
}
}
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.
s.ContainerCreateCommand = os.Args

if len(inputCommand) > 0 {
// User command overrides data CMD
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
s.Command = inputCommand
}

// SHM Size
Expand Down
4 changes: 3 additions & 1 deletion pkg/specgen/generate/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ func makeCommand(ctx context.Context, s *specgen.SpecGenerator, img *image.Image

finalCommand = append(finalCommand, entrypoint...)

// Only use image command if the user did not manually set an
// entrypoint.
command := s.Command
if command == nil && img != nil {
if command == nil && img != nil && s.Entrypoint == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if image has a entrypoint and the command is not nil? Isn't it supposed to still be
entrypoint + command?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, we will append command to entrypoint as normal. This block only handles getting CMD from the image if the user didn't give us a command.

newCmd, err := img.Cmd(ctx)
if err != nil {
return nil, err
Expand Down
11 changes: 10 additions & 1 deletion test/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ USER mail`
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
SkipIfRemote()
dockerfile := `FROM busybox
Expand All @@ -1154,4 +1154,13 @@ WORKDIR /madethis`
Expect(session.ExitCode()).To(Equal(0))
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")))
})
})