1

I'm running a small tesseract API using docker. The ruby app calls the command line to use tesseract on an image. Before it does so it uses a script to pre-process the image first:

post '/extractText' do
  begin
    bas64Image = Base64.decode64(params[:image])
    imageFile = Tempfile.new(['image', '.jpg'])
    imageFile.write(bas64Image)
    imageFile.close
    `textcleaner #{imageFile.path} #{imageFile.path}`
    output = `tesseract #{imageFile.path} --psm 6 stdout`
    p output
  rescue
    status 402
    return "Error reading image"
  end
  status 200
  return output.to_json
end

the app ignores the line textcleaner #{imageFile.path} #{imageFile.path} currently as it does nothing.

When testing in command line with something like docker run tess textcleaner receipt3.jpg receipt3.jpg i get the following error:

container_linux.go:265: starting container process caused "exec: \"textcleaner\": executable file not found in $PATH"
docker: Error response from daemon: oci runtime error: container_linux.go:265: starting container process caused "exec: \"textcleaner\": executable file not found in $PATH".
ERRO[0000] error waiting for container: context canceled

FROM tesseractshadow/tesseract4re

RUN apt-get update && apt-get install -y build-essential ruby-full libffi-dev libgmp3-dev ruby-dev

WORKDIR /home/work

RUN gem install bundler

COPY Gemfile .
COPY textcleaner /home/work
RUN chmod +x /home/work/textcleaner

RUN bundle install

COPY . /home/work

EXPOSE 8080

CMD bundle exec ruby app.rb

I dont know how to add the file to $PATH. When i do:

COPY textcleaner $PATH
RUN chmod +x $PATH/textcleaner 

I get

chmod: cannot access '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin/textcleaner': Not a directory
The command '/bin/sh -c chmod +x $PATH/textcleaner' returned a non-zero code: 1

on the second line.

Any help would be appreciated

1 Answer 1

2

In your Docker file you should have this line:

ENV PATH /path/to/your/textcleaner:$PATH

read more here https://docs.docker.com/engine/reference/builder/#env

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for replying, when i add ENV PATH textcleaner:$PATH RUN chmod +x $PATH/textcleaner to my Docker file i het this error: chmod: cannot access 'textcleaner:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin/textcleaner': Not a directory
Your command should look like this: ENV PATH /home/work/:$PATH
that gives me a similar error: chmod: cannot access '/home/work/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin/textcleaner': No such file or directory
You don't have to do COPY textcleaner $PATH RUN chmod +x $PATH/textcleaner

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.