如何通过 docker run 将参数传递给 Shell 脚本 [英] How to pass arguments to Shell Script through docker run
本文介绍了如何通过 docker run 将参数传递给 Shell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 docker 世界的新手.我必须调用一个 shell 脚本,该脚本通过 docker 容器获取命令行参数.例如:我的 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 --rm test /file.sh abc
docker run -ti --rm test /file.sh xyz
这篇关于如何通过 docker run 将参数传递给 Shell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文