本文介绍了Docker命令行中的转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
-
echo1 > /tmp/service.cfg
-
/ bin / bash
如何分组和转义此命令以在Docker容器内运行:
docker run -i -t debian / latest echo1> /tmp/service.cfg&&& / bin / bash
上面的命令不起作用,因为它不会在所需的文件中回显首先,然后给我一个shell ...
解决方案
我找到了解决方案,我需要运行 sh
命令与 -c
标志如下:
docker run -i -t debian:latest sh -c'echo1> /tmp/service.cfg&&& cat /tmp/service.cfg'
按预期方式返回1 ...
I have a docker image in which I want to run the following command :
echo "1" > /tmp/service.cfg
/bin/bash
How can I group and escape this command to run it within a docker container :
docker run -i -t debian/latest echo "1" > /tmp/service.cfg && /bin/bash
The command above doesn't works as it doesn't echo in the desired file first and then give me the hand in a shell...
解决方案
I found the solution, I needed to run the sh
command with the -c
flag like this :
docker run -i -t debian:latest sh -c 'echo "1" > /tmp/service.cfg && cat /tmp/service.cfg'
This returns 1 as expected...
这篇关于Docker命令行中的转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!