bash 如何在 Dockerfile 中运行脚本文件(.sh 文件)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38264167/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:52:22  来源:igfitidea点击:

How to run script file(.sh file) inside Dockerfile?

bashdockerdockerfile

提问by kalyani chaudhari

I am creating a Docker image. I have 'install.sh' script file and want to run this script file in Dockerfile.

我正在创建一个 Docker 镜像。我有“install.sh”脚本文件,想在 Dockerfile 中运行这个脚本文件。

How should i do this ?

我该怎么做?

回答by kalyani chaudhari

Steps as follows :

步骤如下:

  1. Copy '.sh' file to container

    COPY install.sh .
    
  2. Executing '.sh' file

    RUN ./install.sh
    
  1. 将“.sh”文件复制到容器

    COPY install.sh .
    
  2. 执行“.sh”文件

    RUN ./install.sh
    

'install.sh' file should be in current working directory else you can specify path.

'install.sh' 文件应该在当前工作目录中,否则您可以指定路径。

回答by anubhava

Inside Dockerfile, just add call to your script using RUNcommand as:

在里面Dockerfile,只需使用以下RUN命令添加对脚本的调用:

RUN /path/to/install.sh