自定义Docker映像不继承CMD [英] Custom Docker image doesn't inherit CMD

查看:85
本文介绍了自定义Docker映像不继承CMD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用以下Dockerfile构建的映像:

I have an image built using the following Dockerfile:

FROM php:7-fpm
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
ENTRYPOINT ["docker-entrypoint"]

它使用以下bash脚本的自定义入口点:

It uses a custom entrypoint which is the following bash script:

#!/bin/bash
set -e
echo "STARTING PHP FPM, CMD $@"
docker-php-entrypoint "$@"

在其 Dockerfile CMD [ php-fpm]

现在,我希望此命令在映像中被继承。但是,当我运行图像时,该命令为空。这是 docker run 命令的输出:

Now I expected this command to be inherited in my image. However, when I run the image, the command is empty. Here is the output of the docker run command:


启动PHP FPM,CMD

STARTING PHP FPM, CMD

但是,如果我将 CMD [ php-fpm] 复制到自定义<$的末尾c $ c> Dockerfile ,输出为

However, if I copy CMD ["php-fpm"] to the end of my custom Dockerfile, the output is


启动PHP FPM,CMD php-fpm

STARTING PHP FPM, CMD php-fpm

[2017年11月1日20:04:02]注意:fpm正在运行,pid 7

[01-Nov-2017 20:04:02] NOTICE: fpm is running, pid 7

[2017年11月1日20:04:02]注意:已准备好处理连接

[01-Nov-2017 20:04:02] NOTICE: ready to handle connections

为什么不继承父级的 CMD 指令?

Why isn't the parent's CMD directive inherited?

推荐答案

这种行为试图变得更加直观,但是我同意这有点令人困惑。您会在此处看到原始问题。问题在于,大多数人在子图像中定义 ENTRYPOINT 不再需要父图像中的 CMD

This behavior is trying to be more intuitive, but I agree that it's a bit confusing. You see the original issue here. That problem was that most people defining the ENTRYPOINT in a child image no longer wanted the CMD from the parent image.

根据当前行为,如果在子图像中定义 ENTRYPOINT ,则 CMD 将从父图像中删除,因此如果需要进行设置,则需要重新定义。

With the current behavior, if you define an ENTRYPOINT in a child image, the CMD from the parent image will be null'd out, so you'll need to redefine it if you need to have it set.

这篇关于自定义Docker映像不继承CMD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆