如何通过docker run将参数传递给Shell脚本 [英] How to pass arguments to Shell Script through docker run
本文介绍了如何通过docker run将参数传递给Shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是docker世界的新手.我必须调用一个通过Docker容器获取命令行参数的Shell脚本. 例如:我的shell脚本如下:
I am new to the docker world. I have to invoke a shell script that takes command line arguments through a docker container. Ex: My shell script looks like:
#!bin/bash
echo $1
Dockerfile看起来像这样:
Dockerfile looks like this:
FROM ubuntu:14.04
COPY ./file.sh /
CMD /bin/bash file.sh
我不确定在运行容器时如何传递参数
I am not sure how to pass the arguments while running the container
推荐答案
使用相同的file.sh
#!/bin/bash
echo $1
使用现有的Dockerfile构建映像:
Build the image using the existing Dockerfile:
docker build -t test .
使用参数abc
或xyz
或其他方式运行图像.
Run the image with arguments abc
or xyz
or something else.
docker run -ti test /file.sh abc
docker run -ti test /file.sh xyz
这篇关于如何通过docker run将参数传递给Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文