docker 镜像含有entrypoint信息启动方式以及entrypoint相关介绍

我们经常在启动某些镜像时会遇到如下语法错误,这通常是镜像元信息中的Entrypoint导致的。

docker run -it yuelai:2.0 /bin/bash 
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"/bin/bash /home/yuelai/hello.sh\": stat /bin/bash /home/yuelai/hello.sh: no such file or directory": unknown.
ERRO[0000] error waiting for container: context canceled

Dockerfile 如下:

FROM yuelai:1.0

ENV workdir=/home/yuelai
WORKDIR ${workdir}
RUN mkdir -p ${workdir}
COPY hello.sh ${workdir}
ENTRYPOINT ["/home/yuelai/hello.sh"]
CMD ["world"]

构建过程如下

docker build  -t yuelai:2.0 .
Sending build context to Docker daemon  3.072kB
Step 1/7 : FROM yuelai:1.0
 ---> 703892107d70
Step 2/7 : ENV workdir=/home/yuelai
 ---> Running in 907be255ce79
Removing intermediate container 907be255ce79
 ---> 8001d9de5f9b
Step 3/7 : WORKDIR ${workdir}
 ---> Running in 9ba9b4e4cb3f
Removing intermediate container 9ba9b4e4cb3f
 ---> 92675373db89
Step 4/7 : RUN mkdir -p ${workdir}
 ---> Running in 78a27b6757d8
Removing intermediate container 78a27b6757d8
 ---> 9403ec0c1998
Step 5/7 : COPY hello.sh ${workdir}
 ---> 32807468e22f
Step 6/7 : ENTRYPOINT ["/home/yuelai/hello.sh"]
 ---> Running in 9c096ee532e2
Removing intermediate container 9c096ee532e2
 ---> 6041dce3a7a5
Step 7/7 : CMD ["world"]
 ---> Running in 50f992096629
Removing intermediate container 50f992096629
 ---> dadf1eb5acaa
Successfully built dadf1eb5acaa
Successfully tagged yuelai:2.0

查看镜像元信息Entrypoint:

docker inspect -f {{.Config.Entrypoint}} yuelai:2.0
[/bin/bash /home/yuelai/hello.sh]

那么没有启动脚本,如何启动此镜像呢?有两种方案

按照挂载方式以默认方式启动

docker run -it -v /home/gyy01167504/label_test/:/home/yuelai yuelai:2.0 /bin/bash 
hello /bin/bash

docker run -it -v /home/gyy01167504/label_test/:/home/yuelai yuelai:2.0 'worlds'
hello worlds

docker run -it -v /home/gyy01167504/label_test/:/home/yuelai yuelai:2.0 
hello world

使用entrypoint覆盖的方式(覆盖掉此镜像Dockerfile中Entrypoint的默认执行的shell)

docker run -it --entrypoint /bin/bash yuelai:2.0

[root@d39a85277e9e /home/yuelai]
#

参考文档:

1、https://www.cnblogs.com/mrzzzblog/p/15809793.html

2、https://blog.csdn.net/JineD/article/details/115965328

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值