Docker不能运行脚本可执行文件找不到$ PATH“

我正在使用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东西进行testing时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 

在第二行。

任何帮助,将不胜感激

在你的Docker文件中你应该有这一行:

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

在这里阅读更多https://docs.docker.com/engine/reference/builder/#env