我正在测试与码头,并试图创建自己的码头形象。
我的第一个Dockerfile只是以一个ubuntu作为基本的形象,并安装牛仔。
Dockerfile 1:
FROM ubuntu:latest
RUN apt-get update && apt-get -y install cowsay
ENTRYPOINT ["usr/games/cowsay"]我用
docker build -t test/cowsay .并且可以用
docker run test/cowsay Hello World在接下来的步骤中,我想要创建一个图像,如果没有额外的参数与码头调用,它将默认文本放在牛仔中。对于默认文本,我使用“财富”。
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/fortune .然后用
docker run test/fortune
________________________________________
/ You possess a mind not merely twisted, \
\ but actually sprained. /
----------------------------------------
\
\
.--.
|o_o |
|:_/ |
// \ \
(| | )
/'\_ _/`\
\___)=(___/但是,至少我想使用“财富”中的默认文本,只有在坞调用中没有附加参数的情况下。
如果我打字
码头运行测试/财富你好
/usr/games/fortune -s必须替换为Hello。
_______
< Hello >
-------
\
\
.--.
|o_o |
|:_/ |
// \ \
(| | )
/'\_ _/`\
\___)=(___/有谁知道如何解决我的问题吗?
发布于 2017-09-15 14:49:00
您必须使用bash脚本和ENTRYPOINT来完成这一任务。
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT /entrypoint.shentrypoint.sh
if [ $# -eq 0 ]
then
/usr/games/fortune -s | /usr/games/cowsay -f tux
else
echo $@ | /usr/games/cowsay -f tux
fihttps://stackoverflow.com/questions/46241972
复制相似问题