diff --git a/builder/builder.go b/builder/builder.go index 785f0eb3c3..ccc43f6cc2 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -54,8 +54,6 @@ type Backend interface { ContainerStart(containerID string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error // ContainerWait stops processing until the given container is stopped. ContainerWait(containerID string, timeout time.Duration) (int, error) - // ContainerUpdateCmdOnBuild updates container.Path and container.Args - ContainerUpdateCmdOnBuild(containerID string, cmd []string) error // ContainerCreateWorkdir creates the workdir ContainerCreateWorkdir(containerID string) error diff --git a/builder/dockerfile/dispatchers.go b/builder/dockerfile/dispatchers.go index f83a17ce33..85f82806e9 100644 --- a/builder/dockerfile/dispatchers.go +++ b/builder/dockerfile/dispatchers.go @@ -383,6 +383,11 @@ func run(req dispatchRequest) error { logrus.Debugf("[BUILDER] Command to be executed: %v", runConfig.Cmd) + // Set blank entrypoint to cancel the entrypoint from the parent image + if len(runConfig.Cmd) > 0 { + runConfig.Entrypoint = strslice.StrSlice{""} + } + cID, err := req.builder.create(runConfig) if err != nil { return err diff --git a/builder/dockerfile/dispatchers_test.go b/builder/dockerfile/dispatchers_test.go index 72a82dbd91..0dd3894348 100644 --- a/builder/dockerfile/dispatchers_test.go +++ b/builder/dockerfile/dispatchers_test.go @@ -448,6 +448,7 @@ func TestRunWithBuildArgs(t *testing.T) { getCacheFunc: func(parentID string, cfg *container.Config) (string, error) { // Check the runConfig.Cmd sent to probeCache() assert.Equal(t, cachedCmd, cfg.Cmd) + assert.Equal(t, strslice.StrSlice(nil), cfg.Entrypoint) return "", nil }, } @@ -462,12 +463,14 @@ func TestRunWithBuildArgs(t *testing.T) { // Check the runConfig.Cmd sent to create() assert.Equal(t, cmdWithShell, config.Config.Cmd) assert.Contains(t, config.Config.Env, "one=two") + assert.Equal(t, strslice.StrSlice{""}, config.Config.Entrypoint) return container.ContainerCreateCreatedBody{ID: "12345"}, nil } mockBackend.commitFunc = func(cID string, cfg *backend.ContainerCommitConfig) (string, error) { // Check the runConfig.Cmd sent to commit() assert.Equal(t, origCmd, cfg.Config.Cmd) assert.Equal(t, cachedCmd, cfg.ContainerConfig.Cmd) + assert.Equal(t, strslice.StrSlice(nil), cfg.Config.Entrypoint) return "", nil } diff --git a/builder/dockerfile/internals.go b/builder/dockerfile/internals.go index ec411c4638..094331f1ff 100644 --- a/builder/dockerfile/internals.go +++ b/builder/dockerfile/internals.go @@ -601,12 +601,6 @@ func (b *Builder) create(runConfig *container.Config) (string, error) { b.tmpContainers[c.ID] = struct{}{} fmt.Fprintf(b.Stdout, " ---> Running in %s\n", stringid.TruncateID(c.ID)) - - // override the entry point that may have been picked up from the base image - if err := b.docker.ContainerUpdateCmdOnBuild(c.ID, runConfig.Cmd); err != nil { - return "", err - } - return c.ID, nil } diff --git a/builder/dockerfile/mockbackend_test.go b/builder/dockerfile/mockbackend_test.go index e8647f426c..bdd198ccfe 100644 --- a/builder/dockerfile/mockbackend_test.go +++ b/builder/dockerfile/mockbackend_test.go @@ -73,10 +73,6 @@ func (m *MockBackend) ContainerWait(containerID string, timeout time.Duration) ( return 0, nil } -func (m *MockBackend) ContainerUpdateCmdOnBuild(containerID string, cmd []string) error { - return nil -} - func (m *MockBackend) ContainerCreateWorkdir(containerID string) error { return nil } diff --git a/daemon/update.go b/daemon/update.go index 6e26eeb96a..76e4a3f93f 100644 --- a/daemon/update.go +++ b/daemon/update.go @@ -22,20 +22,6 @@ func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostCon return container.ContainerUpdateOKBody{Warnings: warnings}, nil } -// ContainerUpdateCmdOnBuild updates Path and Args for the container with ID cID. -func (daemon *Daemon) ContainerUpdateCmdOnBuild(cID string, cmd []string) error { - if len(cmd) == 0 { - return nil - } - c, err := daemon.GetContainer(cID) - if err != nil { - return err - } - c.Path = cmd[0] - c.Args = cmd[1:] - return nil -} - func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) error { if hostConfig == nil { return nil diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 5ee64cbe4b..2e9b897d0f 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -337,13 +337,13 @@ func (s *DockerSuite) TestBuildOnBuildCmdEntrypointJSON(c *check.C) { name1 := "onbuildcmd" name2 := "onbuildgenerated" - buildImageSuccessfully(c, name1, build.WithDockerfile(` + cli.BuildCmd(c, name1, build.WithDockerfile(` FROM busybox ONBUILD CMD ["hello world"] ONBUILD ENTRYPOINT ["echo"] ONBUILD RUN ["true"]`)) - buildImageSuccessfully(c, name2, build.WithDockerfile(fmt.Sprintf(`FROM %s`, name1))) + cli.BuildCmd(c, name2, build.WithDockerfile(fmt.Sprintf(`FROM %s`, name1))) result := cli.DockerCmd(c, "run", name2) result.Assert(c, icmd.Expected{Out: "hello world"})