Allow unset --entrypoint
in docker run
or docker create
This fix tries to address the issue raised in #23498 to allow unset `--entrypoint` in `docker run` or `docker create`. This fix checks the flag `--entrypoint` and, in case `--entrypoint=` (`""`) is passed, unset the Entrypoint during the container run. Additional integration tests have been created to cover changes in this fix. This fix fixes #23498. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
5605510bb6
commit
c8d3ee8093
4 changed files with 65 additions and 0 deletions
|
@ -240,6 +240,10 @@ func (daemon *Daemon) mergeAndVerifyConfig(config *containertypes.Config, img *i
|
|||
return err
|
||||
}
|
||||
}
|
||||
// Reset the Entrypoint if it is [""]
|
||||
if len(config.Entrypoint) == 1 && config.Entrypoint[0] == "" {
|
||||
config.Entrypoint = nil
|
||||
}
|
||||
if len(config.Entrypoint) == 0 && len(config.Cmd) == 0 {
|
||||
return fmt.Errorf("No command specified")
|
||||
}
|
||||
|
|
|
@ -478,3 +478,31 @@ func (s *DockerSuite) TestCreate64ByteHexID(c *check.C) {
|
|||
|
||||
dockerCmd(c, "create", imageID)
|
||||
}
|
||||
|
||||
// Test case for #23498
|
||||
func (s *DockerSuite) TestCreateUnsetEntrypoint(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "test-entrypoint"
|
||||
dockerfile := `FROM busybox
|
||||
ADD entrypoint.sh /entrypoint.sh
|
||||
RUN chmod 755 /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
CMD echo foobar`
|
||||
|
||||
ctx, err := fakeContext(dockerfile, map[string]string{
|
||||
"entrypoint.sh": `#!/bin/sh
|
||||
echo "I am an entrypoint"
|
||||
exec "$@"`,
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
defer ctx.Close()
|
||||
|
||||
_, err = buildImageFromContext(name, ctx, true)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
out, _ := dockerCmd(c, "create", "--entrypoint=", name, "echo", "foo")
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(id, check.Not(check.Equals), "")
|
||||
out, _ = dockerCmd(c, "start", "-a", id)
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "foo")
|
||||
}
|
||||
|
|
|
@ -4497,3 +4497,33 @@ func (s *DockerSuite) TestRunAddHostInHostMode(c *check.C) {
|
|||
out, _ := dockerCmd(c, "run", "--add-host=extra:1.2.3.4", "--net=host", "busybox", "cat", "/etc/hosts")
|
||||
c.Assert(out, checker.Contains, expectedOutput, check.Commentf("Expected '%s', but got %q", expectedOutput, out))
|
||||
}
|
||||
|
||||
// Test case for #23498
|
||||
func (s *DockerSuite) TestRunUnsetEntrypoint(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
name := "test-entrypoint"
|
||||
dockerfile := `FROM busybox
|
||||
ADD entrypoint.sh /entrypoint.sh
|
||||
RUN chmod 755 /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
CMD echo foobar`
|
||||
|
||||
ctx, err := fakeContext(dockerfile, map[string]string{
|
||||
"entrypoint.sh": `#!/bin/sh
|
||||
echo "I am an entrypoint"
|
||||
exec "$@"`,
|
||||
})
|
||||
c.Assert(err, check.IsNil)
|
||||
defer ctx.Close()
|
||||
|
||||
_, err = buildImageFromContext(name, ctx, true)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
out, _ := dockerCmd(c, "run", "--entrypoint=", "-t", name, "echo", "foo")
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "foo")
|
||||
|
||||
// CMD will be reset as well (the same as setting a custom entrypoint)
|
||||
_, _, err = dockerCmdWithError("run", "--entrypoint=", "-t", name)
|
||||
c.Assert(err, check.NotNil)
|
||||
c.Assert(err.Error(), checker.Contains, "No command specified")
|
||||
}
|
||||
|
|
|
@ -366,6 +366,9 @@ func Parse(flags *pflag.FlagSet, copts *ContainerOptions) (*container.Config, *c
|
|||
}
|
||||
if copts.flEntrypoint != "" {
|
||||
entrypoint = strslice.StrSlice{copts.flEntrypoint}
|
||||
} else if flags.Changed("entrypoint") {
|
||||
// if `--entrypoint=` is parsed then Entrypoint is reset
|
||||
entrypoint = []string{""}
|
||||
}
|
||||
|
||||
ports, portBindings, err := nat.ParsePortSpecs(copts.flPublish.GetAll())
|
||||
|
|
Loading…
Reference in a new issue