我正在使用docker运行一个小的tesseract API。 ruby应用程序调用命令行在图像上使用tesseract。在此之前,它首先使用脚本预处理图像:
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
该应用程序忽略了当前行textcleaner #{imageFile.path} #{imageFile.path}
,因为它什么都不做。
在命令行中使用类似docker run tess textcleaner receipt3.jpg receipt3.jpg
的内容进行测试时出现以下错误:
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
我不知道如何将文件添加到$ PATH。当我这样做时:
COPY textcleaner $PATH
RUN chmod +x $PATH/textcleaner
我得到了
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
在第二行。
任何帮助将不胜感激
答案 0 :(得分:2)
在你的Docker文件中你应该有这一行:
ENV PATH /path/to/your/textcleaner:$PATH
在此处阅读更多内容https://docs.docker.com/engine/reference/builder/#env