[英]executing shell command in docker composer gives me error
I'm trying to execute shell command in docker-compose.yml.我正在尝试在 docker-compose.yml 中执行 shell 命令。 Code is:代码是:
command: bash -c mkdir /opt/wa/usr/install_templates
When I do:当我做:
sudo docker-compose up serviceA
it gives me:它给了我:
serviceA | mkdir: missing operand
When you use bash -c
, it runs the first string after the -c
flag.当您使用bash -c
时,它会运行-c
标志之后的第一个字符串。 See this SO answer for more information.有关更多信息,请参阅此 SO 答案。 Docker is reading your command bash -c mkdir /path/
and your bash command is just running mkdir
in a bash subshell, causing that error. Docker is reading your command bash -c mkdir /path/
and your bash command is just running mkdir
in a bash subshell, causing that error.
You don't need to put bash -c
before your commands in a docker-compose file.您不需要将bash -c
放在 docker-compose 文件中的命令之前。 The Docker engine will handle running it in a shell for you and you can simply write the command you want to be run. Docker 引擎将为您处理在 shell 中运行它,您只需编写要运行的命令即可。 I'd suggest replacing your command with this:我建议用这个替换你的命令:
command: mkdir /opt/wa/usr/install_templates
Alternatively, you could try putting the entire command into a string if you want to force the command to be run in bash:或者,如果您想强制命令在 bash 中运行,您可以尝试将整个命令放入字符串中:
command: bash -c "mkdir /opt/wa/usr/install_templates"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.