简体   繁体   中英

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). 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:

To see the docker container id

docker container ls 

To enter in bash inside a container.

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 . 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.

As mentioned by @Fra, override the entrypoint and run the command manually.

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. So you can convert files inside your containers using docker exec and then run 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

#!/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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