Docker in practice: pipe stdin i
2019-08-26 本文已影响0人
Star_C
Scenario
You are on a machine that does not have tr
. You want to use tr
to quickly edit a file ./my-article.md
and delete all "
s. You cannot install anything but you can do it with the pre-installed docker
Solution
docker run \ # start docker
--rm \ # remove container after you finish edit
-i \ # this is IMPORTANT, to allow stdin piped into docker instance
jare/alpine-vim \ # specify image
tr -d '"' \ # specify command
< ./my-article.md \ # pipe the file into docker program, which is tr in this case
> ./my-article-quotes-removed.md \ # save output to a file in the machine!