Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
替换dockerfile中cmd的第一个值_Docker_Dockerfile - Fatal编程技术网

替换dockerfile中cmd的第一个值

替换dockerfile中cmd的第一个值,docker,dockerfile,Docker,Dockerfile,我正在测试docker,并尝试创建自己的docker图像 我的第一个Dockerfile只是以ubuntu为基本映像并安装cowsay Dockerfile 1: FROM ubuntu:latest RUN apt-get update && apt-get -y install cowsay ENTRYPOINT ["usr/games/cowsay"] 我用它来塑造形象 docker build -t test/cowsay . docker build -t test

我正在测试docker,并尝试创建自己的docker图像

我的第一个Dockerfile只是以ubuntu为基本映像并安装cowsay

Dockerfile 1:

FROM ubuntu:latest
RUN apt-get update && apt-get -y install cowsay
ENTRYPOINT ["usr/games/cowsay"]
我用它来塑造形象

docker build -t test/cowsay .
docker build -t test/fortune .
并且可以运行它

docker run test/cowsay Hello World
docker run test/fortune


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

在下一步中,我想创建一个图像,如果docker调用没有其他参数,它会在cowsay中放置默认文本。对于默认文本,我使用fortune

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
我用它来塑造形象

docker build -t test/cowsay .
docker build -t test/fortune .
并运行它

docker run test/cowsay Hello World
docker run test/fortune


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

但是,至少我希望只有在docker调用中没有其他参数时才使用fortune的默认文本

如果我打字

docker运行测试/财富你好

/usr/games/fortune-s必须替换为Hello

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

有人知道如何解决我的问题吗?

您必须使用bash脚本和
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