【问题标题】:Using ENTRYPOINT in a Dockerfile makes the base image's CMD be ignored在 Dockerfile 中使用 ENTRYPOINT 会使基础镜像的 CMD 被忽略
【发布时间】:2016-08-11 10:27:17
【问题描述】:

看起来好像当我的 Dockerfile 使用 ENTRYPOINT 脚本时,它的基本映像的 CMD 被忽略了。谁能告诉我为什么和/或在文档中解释了这种行为的位置?

这是一个扩展官方 php:7.0-fpm 镜像(使用 CMD ["php-fpm"])的 Dockerfile 示例。在入口点脚本中,我希望 $@ 变量包含字符串 php-fpm,但它是空的。

marc@imac-marc:/opt/php-docker$ cat Dockerfile-php
FROM php:7.0-fpm
COPY utils/entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

marc@imac-marc:/opt/php-docker$ cat utils/entrypoint.sh 
#!/usr/bin/env bash
echo "CMD = $@"

marc@imac-marc:/opt/php-docker$ docker build -t me:myImage -f Dockerfile-php .
Sending build context to Docker daemon   276 kB
Step 1 : FROM php:7.0-fpm
 ---> d66add11c05d
Step 2 : COPY utils/entrypoint.sh /usr/local/bin/
 ---> a62ef60a202b
Removing intermediate container 20bd7782844e
Step 3 : RUN chmod +x /usr/local/bin/entrypoint.sh
 ---> Running in 27af4ffbd6c0
 ---> 77fba35c804d
Removing intermediate container 27af4ffbd6c0
Step 4 : ENTRYPOINT /usr/local/bin/entrypoint.sh
 ---> Running in 6779b16542ec
 ---> 326970218669
Removing intermediate container 6779b16542ec
Successfully built 326970218669

marc@imac-marc:/opt/php-docker$ docker run me:myImage
CMD = 

如果我将CMD ["php-fpm"] 添加到我的 Dockerfile 中,它会按预期工作。

【问题讨论】:

    标签: docker dockerfile


    【解决方案1】:

    请参阅https://github.com/moby/moby/issues/5147 - 它解释了何时以及为何实施此行为。

    【讨论】:

      猜你喜欢
      • 2017-08-31
      • 1970-01-01
      • 2018-12-31
      • 2019-06-09
      • 1970-01-01
      • 1970-01-01
      • 2021-04-23
      • 2019-07-11
      • 1970-01-01
      相关资源
      最近更新 更多