我们经常在启动某些镜像时会遇到如下语法错误,这通常是镜像元信息中的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