简体   繁体   English

如何将 bash 放入 docker 容器中

[英]How to bash into a docker container

trying to bash into container and do a for loop which simply performs a command (which works on a single file by the way).试图将 bash 放入容器并执行一个 for 循环,该循环仅执行一个命令(顺便说一下,它适用于单个文件)。 it even seems to echo the right command...what did I forget Untitled它甚至似乎呼应了正确的命令……我忘记了什么无标题

for pdf in *.pdf ;
do 
 docker run --rm -v "$(pwd):/home/docker" leofcardoso/pdf2pdfocr -g jpeg2000 -v -i '\'''$pdf''\''';
done

You can bash in a container with this commands:您可以使用以下命令在容器中 bash:

To see the docker container id查看 docker 容器 id

docker container ls 

To enter in bash inside a container.在容器内输入 bash。

docker exec -it CONTAINER_ID bash

First thing, you are not allocating tty in the docker run command and the docker container dies soon after converting files .首先,您没有在 docker 运行命令中分配tty ,并且 docker 容器在转换文件后很快就会死掉。 Here is main process of container这是容器的主要过程

#!/bin/bash

cd /home/docker
exec pdf2pdfocr.py "$@"

So, in this case, the life of this container is the life of exec pdf2pdfocr.py "$@" command.所以,在这种情况下,这个容器的生命周期就是exec pdf2pdfocr.py "$@"命令的生命周期。

As mentioned by @Fra, override the entrypoint and run the command manually.正如@Fra 所提到的,覆盖入口点并手动运行命令。

docker run --rm -v "$(pwd):/home/docker" -it --entrypoint /bin/bash leofcardoso/pdf2pdfocr

but in the above run command, docker container will do not a thing and will just allocate the tty and the bash will open.但是在上面的运行命令中,docker 容器不会做任何事情,只会分配tty ,bash 将打开。 So you can convert files inside your containers using docker exec and then run pdf2pdfocr.py -g jpeg2000 -v -i mypdf.pdf因此,您可以使用 docker exec 转换容器内的文件,然后运行pdf2pdfocr.py -g jpeg2000 -v -i mypdf.pdf

So, if you want to run with override entry point then you can try.因此,如果您想使用覆盖入口点运行,那么您可以尝试。

docker run -it --rm --entrypoint /bin/bash -v "$(pwd):/home/docker" leofcardoso/pdf2pdfocr -c "pdf2pdfocr.py -g jpeg2000 -v -i mypdf.pdf"

or with the bash script或使用 bash 脚本

#!/bin/bash
for pdf in *.pdf ;
do
 echo "converting $pdf" 
 docker run -it --rm --entrypoint /bin/bash -v "$(pwd):/home/docker" leofcardoso/pdf2pdfocr -c "pdf2pdfocr.py -g jpeg2000 -v -i  $pdf"
done

But the container will die after completing the conversion.但是容器在完成转换后会死掉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM