[英]How to docker-compose run in windows?
How to use this command in windows 10 familly : 如何在Windows 10 familly中使用此命令:
docker-compose run api composer install --no-interaction
Example: 例:
docker-compose run api composer install --no-interaction
- Interactive mode is not yet supported on Windows.
Please pass the -d flag when using `docker-compose run`.
Is it possible ? 可能吗 ?
Do you have an example ? 你有一个例子吗?
The interactive mode support for docker-compose on Windows is tracked by issue 2836 which proposes some alternatives: 问题2836跟踪了对Windows上的docker-compose的交互模式支持,该问题提出了一些替代方案:
Use bash from within the container: 在容器中使用bash:
docker exec -it MY_CONTAINER bash
Use a docker-compose-run script by Rodrigo Baron : 使用Rodrigo Baron的docker-compose-run脚本 :
Script ( put the function in ~/.zshrc
or ~/.bashrc
in a Windows git bash shell for instance): 脚本(例如,将函数放在
~/.zshrc
或~/.bashrc
中的Windows git bash shell中):
#!/bin/bash
function docker-compose-run() {
if [ "$1" = "-f" ] || [ "$1" = "--file" ] ; then
docker exec -i $(docker-compose -f $2 ps $3 |grep -m 1 $3 | cut -d ' ' -f1) "${@:4}"
else
docker exec -i $(docker-compose ps $1 | grep -m 1 $1 | cut -d ' ' -f1) "${@:2}"
fi
}
docker-compose-run "$@"
Usage: 用法:
usage: 用法:
docker-compose-run web rspec
# or:
docker-compose-run -f docker-compose.development.yml web rspec
Simpler alternative is to use option -d
and to get logs 更简单的替代方法是使用选项
-d
并获取日志
docker-compose run -rm <service> <command>
is replaced by: 被替换为:
docker-compose-run <service> <command>
For this to work, add this snippet in your ~/.bashrc
: 为此,请在
~/.bashrc
添加此代码段:
docker-compose-run() {
CONTAINER_NAME=$(docker-compose run -d $@)
docker logs -f $CONTAINER_NAME
docker rm $CONTAINER_NAME
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.