Skip to content

Conversation

tianon
Copy link
Contributor

@tianon tianon commented Jun 7, 2023

When running --invoke against images that have Cmd set, the interactions with Entrypoint start to cause issues like the following:

/usr/local/bin/bash: /usr/local/bin/bash: cannot execute binary file

Or:

sh: can't open 'bash': No such file or directory

This patch fixes those by explicitly setting Cmd to be empty if it is unspecified and Entrypoint is being set, which matches docker's behavior:

$ docker image inspect --format '{{ json .Config.Entrypoint }} + {{ json .Config.Cmd }}' bash
["docker-entrypoint.sh"] + ["bash"]
$ docker create --name foo --entrypoint bash bash
$ docker container inspect --format '{{ json .Config.Entrypoint }} + {{ json .Config.Cmd }}' foo
["bash"] + null
$ docker rm foo
$ docker create --name foo bash ls
$ docker container inspect --format '{{ json .Config.Entrypoint }} + {{ json .Config.Cmd }}' foo
["docker-entrypoint.sh"] + ["ls"]

(There are still some weird edge cases in the interaction between the InvokeConfig and the original image config, but this fixes the most irritating for me and the rest are going to be deeper changes that are possibly less acceptable. 😅)

When running `--invoke` against images that have `Cmd` set, the interactions with `Entrypoint` start to cause issues like the following:

    /usr/local/bin/bash: /usr/local/bin/bash: cannot execute binary file

Or:

    sh: can't open 'bash': No such file or directory

This patch fixes those by explicitly setting `Cmd` to be empty if it is unspecified and `Entrypoint` is being set, which matches `docker`'s behavior:

    $ docker image inspect --format '{{ json .Config.Entrypoint }} + {{ json .Config.Cmd }}' bash
    ["docker-entrypoint.sh"] + ["bash"]
    $ docker create --name foo --entrypoint bash bash
    $ docker container inspect --format '{{ json .Config.Entrypoint }} + {{ json .Config.Cmd }}' foo
    ["bash"] + null
    $ docker rm foo
    $ docker create --name foo bash ls
    $ docker container inspect --format '{{ json .Config.Entrypoint }} + {{ json .Config.Cmd }}' foo
    ["docker-entrypoint.sh"] + ["ls"]

(There are still some weird edge cases in the interaction between the `InvokeConfig` and the original image config, but this fixes the most irritating for me and the rest are going to be deeper changes that are possibly less acceptable. 😅)

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
@tianon
Copy link
Contributor Author

tianon commented Jun 7, 2023

The easiest way to reproduce the first of my examples is with a Dockerfile of FROM bash and --invoke entrypoint=bash (because it has Cmd set to bash, so without this change that ends up trying to run bash bash).

@jedevc
Copy link
Collaborator

jedevc commented Jun 8, 2023

Nice, thanks @tianon ❤️

@jedevc jedevc merged commit c30bcad into docker:master Jun 8, 2023
@tianon tianon deleted the invoke-entrypoint-fixes branch June 8, 2023 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants