Docker container with entrypoint variable expansion and CMD parameters

后端 未结 2 455
执念已碎
执念已碎 2021-01-17 08:09

I want to create a Docker Image that acts as an executable for which the user passes a token as an environment variable. The executable has sub commands that the user should

2条回答
  •  执念已碎
    2021-01-17 09:10

    With /bin/sh -c "script" syntax, anything after the -c argument becomes an argument to your script. You can reach them with $0 and $@ as part of your /bin/sh script:

    ENTRYPOINT ["/bin/sh", "-c", "exec /usr/bin/mycmd --token=$MY_TOKEN $0 $@"]
    CMD ["pull", "stuff"]
    

    Note that you could also change your entrypoint to be a shell script added to your image that runs exec /usr/bin/mycmd --token=$MY_TOKEN "$@" and execute that shell script with docker's exec syntax:

    ENTRYPOINT ["/entrypoint.sh"]
    

提交回复
热议问题