如何在Alpine Docker容器中运行Bash脚本?
我的目录仅包含两个文件,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
但是,如果尝试run
这样做,则会executable file not found in $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特有的)?
-
Alpine附带ash作为默认外壳,而不是
bash
。所以你可以
-
有一个shebang将/ bin / bash定义为sayhello.sh的第一行,因此您的文件sayhello.sh将以bin / sh开头
#!/bin/sh
-
就像您期望的那样,在您的Alpine映像中安装Bash,就像在Dockerfile中这样一行:
RUN apk add --no-cache --upgrade bash
-
-
如何在基于Alpine的Docker映像中使用bash?
2021-02-01 关注 0 浏览167 1答案
-
在Alpine docker容器中运行geckodriver
2021-02-01 关注 0 浏览293 1答案
-
如何在Dockerfile中为Docker容器设置bash别名?
2021-02-01 关注 0 浏览411 1答案
-
如何在Docker容器中运行Cron作业?
2021-02-01 关注 0 浏览231 1答案
-
如何在Docker容器中运行Cron作业
2021-02-01 关注 0 浏览187 1答案
-
如何在 docker 容器中运行 cron 作业?
2022-03-22 关注 0 浏览34 1答案
-
如何在以容器运行的Jenkins中运行Docker
2021-01-31 关注 0 浏览112 1答案
-
使用“退出”后如何保留docker alpine容器?
2021-02-01 关注 0 浏览174 1答案
-
Docker容器启动后如何自动运行脚本
2021-02-01 关注 0 浏览335 1答案
-
Docker:如何将 bash 与基于 Alpine 的 docker 映像一起使用?
2022-04-11 关注 0 浏览22 1答案