从基于 alpine 的 docker 运行 bash 脚本 [英] Running a bash script from alpine based docker

查看:55
本文介绍了从基于 alpine 的 docker 运行 bash 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Dockerfile 包含:

I have Dockerfile containing:

FROM alpine

COPY script.sh /script.sh

CMD ["./script.sh"]

和一个 script.sh(具有可执行权限):

and a script.sh (with executable permission):

#!/bin/bash
echo "hello world from script file"

当我跑步时

docker run --name testing fff0e5c81ca0

其中 fff0e5c81ca0 是构建后的 ID,我收到一个错误

where fff0e5c81ca0 is the id after building, I get an error

standard_init_linux.go:195: exec user process caused "no such file or directory"

那我该如何解决呢?

推荐答案

要在基于 alpine 的图像中运行 bash 脚本,您需要执行任一操作

To run a bash script in alpine based image, you need to do either one

  1. 安装 bash

  1. Install bash

$ RUN apk add --update bash

  • 在脚本中使用 #!/bin/sh 而不是 #!/bin/bash

    你需要做这两项或两项中的任何一项

    You need to do any one of these two or both

    或者,就像@Maroun 在 注释,您可以更改您的 CMD 以执行您的 bash 脚本

    Or, like @Maroun's answer in comment, you can change your CMD to execute your bash script

    CMD ["sh", "./script.sh"]
    

    这篇关于从基于 alpine 的 docker 运行 bash 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆