Default Docker entrypoint

早过忘川 提交于 2019-12-06 17:18:07

问题


I am creating an image from another image that set a specific entrypoint. However I want my image to have default one. How do I reset the ENTRYPOINT?

I tried the following Dockerfile:

FROM some-image
ENTRYPOINT ["/bin/sh", "-c"]

Unfortunately it doesn't work like the default entrypoint as it need the command to be quoted.

docker run myimage ls -l /    # "-l /" arguments are ignored
file1 file2 file3             # files in current working directory

docker run myimage "ls -l /"  # works correctly

How do I use commands without quoting?


回答1:


To disable an existing ENTRYPOINT, set an empty array in your docker file

ENTRYPOINT []

Then your arguments to docker run will exec as normal.

The reason your ENTRYPOINT ["/bin/sh", "-c"] requires quoted strings is that without the quotes, the arguments to ls are being passed to sh instead.

Unquoted results in lots of arguments being sent to sh

"/bin/sh", "-c", "ls", "-l", "/"

Quoting allows the complete command (sh -c) to be passed on to sh as one argument.

"/bin/sh", "-c", "ls -l /"



回答2:


This isn't really related to docker. Try running the following:

/bin/sh -c echo foo

/bin/sh -c "echo foo"

The -c means that /bin/sh only picks up one argument. So removing the -c from the entrypoint you define should fix it. This is more flexible than resetting the entry point; e.g. you can do this to use Software Collections:

ENTRYPOINT ["scl", "enable", "devtoolset-4", "--", "bash"]



来源:https://stackoverflow.com/questions/37634483/default-docker-entrypoint

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!