从基于 alpine 的 docker 运行 bash 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48597225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running a bash script from alpine based docker
提问by Mumbaikar007
I have Dockerfile containing:
我有 Dockerfile 包含:
FROM alpine
COPY script.sh /script.sh
CMD ["./script.sh"]
and a script.sh
(with executable permission):
和一个script.sh
(具有可执行权限):
#!/bin/bash
echo "hello world from script file"
when I run
当我跑
docker run --name testing fff0e5c81ca0
where fff0e5c81ca0 is the id after building, I get an error
其中 fff0e5c81ca0 是构建后的 ID,出现错误
standard_init_linux.go:195: exec user process caused "no such file or directory"
So how can I solve it?
那么我该如何解决呢?
回答by Mir Shahriar Sabuj
To run a bash script in alpine based image, you need to do either one
要在基于 alpine 的图像中运行 bash 脚本,您需要执行以下任一操作
Install bash
$ RUN apk add --update bash
Use
#!/bin/sh
in script instead of#!/bin/bash
安装 bash
$ RUN apk add --update bash
#!/bin/sh
在脚本中使用而不是#!/bin/bash
You need to do any one of these two or both
你需要做这两项或两项中的任何一项
Or, like @Maroun's answer in comment, you can change your CMD to execute your bash script
或者,就像@Maroun 在评论中的回答一样,您可以更改 CMD 以执行您的 bash 脚本
CMD ["sh", "./script.sh"]
回答by yuen26
Your Dockerfile may look like this:
您的 Dockerfile 可能如下所示:
FROM openjdk:8u171-jre-alpine3.8
COPY script.sh /script.sh
CMD ["sh", "./script.sh"]