gpt4 book ai didi

docker - Dockerfile在shell入口点之前运行入口点

转载 作者:行者123 更新时间:2023-12-02 18:55:53 24 4
gpt4 key购买 nike

我想在将参数传递给shell入口点之前在运行时进行最后一分钟的设置,为实现这一点,我谨记以下几点:

ENTRYPOINT ./run_binary ${args}; /bin/sh -c
CMD ./run_binary

但是,通过执行此操作,似乎没有任何 CMD参数将其设置为shell入口点。有没有解决的办法?我只是想在二进制文件上运行设置步骤,然后再将控制权交还给Shell入口点(然后通过 CMD交给USER)。

最佳答案

您可以使用中间构建镜像来触发原始Dockerfile中的ONBUILD语句,请参阅:https://docs.docker.com/engine/reference/builder/#/onbuild

The ONBUILD instruction adds to the image a trigger instruction to be executed at a later time, when the image is used as the base for another build. The trigger will be executed in the context of the downstream build, as if it had been inserted immediately after the FROM instruction in the downstream Dockerfile.

This is useful if you are building an image which will be used as a base to build other images, for example an application build environment or a daemon which may be customized with user-specific configuration.



关于CMD和ENTRYPOINT,请参阅: https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact
  • Dockerfile应该指定CMDENTRYPOINT中的至少一个
    命令。
  • 使用容器作为容器时应定义
  • ENTRYPOINT 可执行文件。
  • CMD应该用作定义默认参数的方式
    ENTRYPOINT命令或用于在命令行中执行即席命令
    容器。
  • 当使用替代方法运行容器时,
  • CMD将被覆盖
    论点。
  • 关于docker - Dockerfile在shell入口点之前运行入口点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39042300/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com