gpt4 book ai didi

Docker 构建输出脚本从 dockerfile 运行

转载 作者:行者123 更新时间:2023-12-02 18:52:50 25 4
gpt4 key购买 nike

我正在运行一个

docker build -t $NAME -f Dockerfile.test .

命令。

在我的 Dockerfile.test最后我有(我正在复制某些东西以使一切正常)
CMD["bin/bash", "-c", "bash /run-script.sh && bash /run-another-script.sh"]

当我在 Jenkins 中查看构建阶段时,我只能看到一切正常,
CMD /bin/bash -c bash /run-script.sh && bash /run-another-script.sh

已执行,并且由于我在这些脚本中运行 sonarqube 扫描,我可以在我的 sonarqube 中看到发生了扫描(这没关系)。

但是由于我在脚本中运行 PHP 单元测试,所以我有点怀疑这部分,因为在 Jenkins 中,这完成得非常快(在我的本地计算机上运行覆盖报告的单元测试大约需要 20 分钟),失败了,或者没有按应有的方式运行。

所以我想看看这些脚本的输出( run-script.shrun-another-script.sh ),以确保一切都按预期工作。

我听说docker不会显示在终端中写入/删除行的脚本的输出,所以这可能是原因(我猜是ofc)。

有没有办法显示输出?

最佳答案

我觉得你很困惑RUNCMD .RUN -命令在构建期间执行(docker build),CMD - 命令在您启动容器时执行( docker run )。
可以肯定的是,我写了一个小测试:

  • 使用命令
    $ docker build -t cmdtest -< 来自centos:7
    运行回声“回声脚本1”> script1.sh
    运行回声“回声脚本2”> script2.sh
    CMD ["bin/bash", "-c", "bash/script1.sh && bash/script2.sh"]
    EOF

  • 不打印任何东西,因为没有执行。但是,在 docker run 打印:
    $ docker run cmdtest
    > script1
    > script2
  • 使用运行
    $ docker build -t cmdtest -< 来自centos:7
    运行回声“回声脚本1”> script1.sh
    运行回声“回声脚本2”> script2.sh
    运行 ["bin/bash", "-c", "bash/script1.sh && bash/script2.sh"]
    EOF

    Sending build context to Docker daemon 2.048 kB...Step 4/4 : RUN bin/bash -c bash /script1.sh && bash /script2.sh---> Running in 7aab2725ed25

    script1script2---> 8ca71d1c67e8



  • 在构建时打印。

    关于Docker 构建输出脚本从 dockerfile 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53264615/

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