替换dockerfile中cmd的第一个值
我正在测试docker,并尝试创建自己的docker图像 我的第一个Dockerfile只是以ubuntu为基本映像并安装cowsay Dockerfile 1:替换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
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