docker run <图像>&lt;多个命令&gt; [英] docker run &lt;IMAGE&gt; &lt;MULTIPLE COMMANDS&gt;

查看:26
本文介绍了docker run <图像>&lt;多个命令&gt;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像这样运行多个命令.

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 <图像>&lt;多个命令&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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