docker run <图像><多个命令> [英] docker run <IMAGE> <MULTIPLE COMMANDS>
问题描述
我正在尝试像这样运行多个命令.
I'm trying to run MULTIPLE commands like this.
docker run image cd /path/to/somewhere && python a.py
但这给了我没有这样的文件或目录"错误,因为它被解释为...
But this gives me "No such file or directory" error because it is interpreted as...
"docker run image cd /path/to/somewhere" && "python a.py"
似乎需要一些转义字符,如"或().
It seems that some ESCAPE characters like "" or () are needed.
所以我也试过
docker run image "cd /path/to/somewhere && python a.py"
docker run image (cd /path/to/somewhere && python a.py)
但是这些都没用.
我搜索了 Docker 运行参考,但没有找到有关 ESCAPE 字符的任何提示.
I have searched for Docker Run Reference but have not find any hints about ESCAPE characters.
推荐答案
在docker中运行多个命令,使用/bin/bash -c
和分号;
>
To run multiple commands in docker, use /bin/bash -c
and semicolon ;
docker run image_name /bin/bash -c "cd /path/to/somewhere; python a.py"
如果我们需要 command2 (python) 当且仅当 command1 (cd) 返回零(无错误)退出状态时才会执行,请使用 &&
而不是 ;代码>
In case we need command2 (python) will be executed if and only if command1 (cd) returned zero (no error) exit status, use &&
instead of ;
docker run image_name /bin/bash -c "cd /path/to/somewhere && python a.py"
这篇关于docker run <图像><多个命令>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!