replacedockerfile中的第一个cmd值

我正在与dockertesting,并尝试创build自己的docker图像。

我的第一个Dockerfile只是一个Ubuntu的基本形象,并安装Cowsay。

Dockerfile 1:

FROM ubuntu:latest RUN apt-get update && apt-get -y install cowsay ENTRYPOINT ["usr/games/cowsay"] 

我build立图像

 docker build -t test/cowsay . 

并可以运行它

 docker run test/cowsay Hello World 

在接下来的步骤中,我想创build一个图像,如果没有额外的参数与泊坞窗调用将默认文本在cowsay。 对于我使用财富的默认文本。

Dockerfile 2

 FROM test/cowsay:latest RUN apt-get update && apt-get -y install fortune ENTRYPOINT [] CMD /usr/games/fortune -s | /usr/games/cowsay -f tux 

我build立图像

 docker build -t test/fortune . 

并运行它

 docker run test/fortune ________________________________________ / You possess a mind not merely twisted, \ \ but actually sprained. / ---------------------------------------- \ \ .--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/ 

但是,至less我想使用来自财富的默认文本,只有在docker调用中没有额外的参数。

如果我input

docker运行testing/财富你好

/ usr / games / fortune -s必须replace为Hello

  _______ < Hello > ------- \ \ .--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/ 

有没有人有一个想法如何解决我的问题?

你将不得不使用bash脚本和ENTRYPOINT来做到这ENTRYPOINT

 COPY entrypoint.sh /entrypoint.sh ENTRYPOINT /entrypoint.sh 

entrypoint.sh

 if [ $# -eq 0 ] then /usr/games/fortune -s | /usr/games/cowsay -f tux else echo $@ | /usr/games/cowsay -f tux fi