在 docker exec 命令中使用“*" [英] Using '*' in docker exec command
问题描述
我正在尝试在正在运行的 docker 容器中运行特定命令.
I am trying to run specific command inside running docker container.
Docker exec -t t1 ls /tmp/sth/*
作为回报,我收到了
ls: cannot access '/tmp/sth/*': No such file or directory
事实上,当我在容器内执行命令时,一切正常.容器使用 Debian,本地机器使用 Windows.我试图找到它,但找不到.
In fact when I execute command while inside container everything works. Container is using Debian and local machine is using Windows. I was trying to find it, but could not.
推荐答案
如果你想在容器内有一个 shell 来扩展你的 glob,你需要......好吧......实际运行一个容器内的外壳.容器外的人看不到容器内的文件(当然),因此它传递 ls
文字模式,而不是您想要的目录中的文件列表.
If you want a shell inside the container to expand your glob, you need to... well... actually run a shell inside the container. The one outside the container can't see files inside the container (of course), so it passes ls
the literal pattern, not a list of files in the directory as you intend.
因此:
docker exec -t t1 sh -c "ls /tmp/sth/*"
...请注意,我通常对命令使用单引号,但由于您的主机是 Windows,因此使用双引号,因为它们更有可能在 cmd.exe
中工作.
...note that I'd usually use single-quotes for the command, but since your host is Windows, using double quotes since they're more likely to work from cmd.exe
.
这篇关于在 docker exec 命令中使用“*"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!