我有一个仅包含两个文件的目录,Dockerfile
和 sayhello.sh
:
.
├── Dockerfile
└── sayhello.sh
Dockerfile
的作用是读取内容。
FROM alpine
COPY sayhello.sh sayhello.sh
CMD ["sayhello.sh"]
并且sayhello.sh
只包含简单的内容
echo hello
Dockerfile
构建成功:
kurtpeek@Sophiemaries-MacBook-Pro ~/d/s/trybash> docker build --tag trybash .
Sending build context to Docker daemon 3.072 kB
Step 1/3 : FROM alpine
---> 665ffb03bfae
Step 2/3 : COPY sayhello.sh sayhello.sh
---> Using cache
---> fe41f2497715
Step 3/3 : CMD sayhello.sh
---> Using cache
---> dfcc26c78541
Successfully built dfcc26c78541
然而,如果我尝试运行
它,我会收到一个$PATH中找不到可执行文件
的错误:
kurtpeek@Sophiemaries-MacBook-Pro ~/d/s/trybash> docker run trybash
container_linux.go:247: starting container process caused "exec: \"sayhello.sh\": executable file not found in $PATH"
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"sayhello.sh\": executable file not found in $PATH".
ERRO[0001] error getting events from daemon: net/http: request canceled
这是什么原因呢?我记得以类似的方式在基于debian:jessie
的镜像中运行脚本。也许这是专门针对Alpine的问题?
这是什么引起的?我记得以类似的方式在基于debian:jessie
的镜像中运行脚本。也许这是Alpine特有的问题吗?
CMD ["sayhello.sh"]
更改为CMD ["./sayhello.sh"]
,问题得到了解决,无需安装Bash。 - codeforester#!/bin/ash
以便正确解释它。 - DaveO