21

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
6
  • 2
    To bash into a container you need to run the image interactively docker run -it <image> bash. This will allow you to see and edit the content Commented Oct 9, 2019 at 12:05
  • Provided that the bash exists in the docker image ... Commented Oct 9, 2019 at 12:08
  • So i see that the base image used by leofcardoso/pdf2pdfocr is ubuntu 18.04 so bash should work Commented Oct 9, 2019 at 12:15
  • you can replace bash with any installed shell (/bin/sh). The post clearly states How to bash... I guess it is installed. Commented Oct 9, 2019 at 12:15
  • 1
    Have you tried docker run -it --entrypoint /bin/bash <image> Commented Oct 9, 2019 at 12:23

2 Answers 2

46

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
Sign up to request clarification or add additional context in comments.

1 Comment

actually this doesn't work in this case. You should have an always running container in order to get inside it but this container is planned to be used as a fast executing container.
6

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.