不能在docker上用ruby / sinatra安装postgres

我正在尝试使用docker做一个tesseract api,但是在安装bundle的时候,我得到这个错误:

Fetching data_mapper 1.2.0 Installing data_mapper 1.2.0 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /var/lib/gems/2.3.0/gems/do_postgres-0.10.17/ext/do_postgres /usr/bin/ruby2.3 -r ./siteconf20171013-5-6l2bdy.rb extconf.rb checking for main() in -lpq... yes checking for libpq-fe.h... yes checking for libpq/libpq-fs.h... yes checking for postgres.h... no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/bin/$(RUBY_BASE_NAME)2.3 --with-pgsql-server-dir --without-pgsql-server-dir --with-pgsql-server-include --without-pgsql-server-include=${pgsql-server-dir}/include --with-pgsql-server-lib --without-pgsql-server-lib=${pgsql-server-dir}/lib --with-pgsql-client-dir --without-pgsql-client-dir --with-pgsql-client-include --without-pgsql-client-include=${pgsql-client-dir}/include --with-pgsql-client-lib --without-pgsql-client-lib=${pgsql-client-dir}/lib --with-pqlib --without-pqlib Could not find PostgreSQL build environment (libraries & headers): Makefile not created To see why this extension failed to compile, please check the mkmf.log which can be found here: /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/do_postgres-0.10.17/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /var/lib/gems/2.3.0/gems/do_postgres-0.10.17 for inspection. Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/do_postgres-0.10.17/gem_make.out An error occurred while installing do_postgres (0.10.17), and Bundler cannot continue. Make sure that `gem install do_postgres -v '0.10.17'` succeeds before bundling. In Gemfile: dm-postgres-adapter was resolved to 1.2.0, which depends on do_postgres The command '/bin/sh -c /bin/bash -l -c "bundle install"' returned a non-zero code: 5 

我的docker文件看起来像这样:

  FROM ubuntu:16.04 RUN apt-get update && apt-get install -y \ ruby-dev \ postgresql postgresql-contrib libpq-dev \ autoconf \ autoconf-archive \ automake \ build-essential \ checkinstall \ cmake \ g++ \ git \ libcairo2-dev \ libcairo2-dev \ libicu-dev \ libicu-dev \ libjpeg8-dev \ libjpeg8-dev \ libpango1.0-dev \ libpango1.0-dev \ libpng12-dev \ libpng12-dev \ libtiff5-dev \ libtiff5-dev \ libtool \ pkg-config \ wget \ xzgv \ zlib1g-dev \ vim \ python-pip # SSH for diagnostic RUN apt-get update && apt-get install -y --allow-downgrades --allow-remove-essential --allow-change-held-packages openssh-server RUN mkdir /var/run/sshd RUN echo 'root:root' | chpasswd RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config # SSH login fix. Otherwise user is kicked off after login RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd ENV NOTVISIBLE "in users profile" RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"] # Directories ENV SCRIPTS_DIR /home/scripts ENV PKG_DIR /home/pkg ENV BASE_DIR /home/workspace ENV LEP_REPO_URL https://github.com/DanBloomberg/leptonica.git ENV LEP_SRC_DIR ${BASE_DIR}/leptonica ENV TES_REPO_URL https://github.com/tesseract-ocr/tesseract.git ENV TES_SRC_DIR ${BASE_DIR}/tesseract ENV TESSDATA_PREFIX /usr/local/share/tessdata RUN mkdir ${SCRIPTS_DIR} RUN mkdir ${PKG_DIR} RUN mkdir ${BASE_DIR} RUN mkdir ${TESSDATA_PREFIX} COPY ./container-scripts/* ${SCRIPTS_DIR}/ RUN chmod +x ${SCRIPTS_DIR}/* RUN ${SCRIPTS_DIR}/repos_clone.sh RUN ${SCRIPTS_DIR}/tessdata_download.sh # Install pytesseract RUN pip install --upgrade pip \ && pip install pytesseract==0.1.6 # Add textcleaner from Fred's ImageMagick Scripts # http://www.fmwconcepts.com/imagemagick/textcleaner/ ADD ./bin/textcleaner /usr/local/bin # Setup app WORKDIR /app ADD . /app RUN /bin/bash -l -c "gem install pg -- --with-pg-lib=/usr/lib" RUN /bin/bash -l -c "gem install bundler" RUN /bin/bash -l -c "bundle install" ENTRYPOINT ["ruby", "app.rb"] # create user tesseract for use with this server RUN groupadd -r tesseract && useradd -r -g tesseract tesseract USER tesseract 

我只是运行一个小的单一端点的sinatra应用程序,你发送图像,它返回文本作为JSON文件,并在这一点上绊脚石。

我已经search了相当数量,并尝试了一些解决scheme,如指向configuration文件的位置,但他们似乎都给出了类似的错误。

任何帮助将是伟大的

为什么要使用ubuntu:16.04就在一开始。 我认为问题在于你的docker环境没有正确设置来运行ruby和bundler。

为了通过这个血腥的设置过程,我build议你使用具有高山或苗条标签的ruby图像,如果存储空间是一个问题。 然后安装过程变得更容易,你避免所有这些错误