在docker镜像上安装具有原生扩展名的gem

时间:2018-03-07 17:30:29

标签: docker rubygems docker-compose dockerfile

我有一个运行php7-fpm图像的web项目。对于这个项目,我需要安装Ruby gem sass。

但是在构建容器时,它没有说它缺少libffi-dev包中的一些头文件。我在Dockerfile开头的软件包安装中添加了软件包。

有谁知道我能做些什么来解决这个问题?

这是我的Dockerfile:

FROM phpdockerio/php7-fpm:latest
# Install selected extensions
RUN apt-get update \
    && apt-get -y --no-install-recommends install php7.0-memcached php7.0-mysql php7.0-redis php7.0-gd php7.0-imagick php7.0-intl php7.0-xdebug php7.0-mbstring \
    && apt-get -y --no-install-recommends install nodejs npm nodejs-legacy vim ruby-full git libffi-dev \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN npm install -g bower
RUN npm install -g less
RUN gem install sass

# If you're using symfony and the vagranted environment, I strongly recommend you change your AppKernel to use the following temporary folders
# for cache, logs and sessions, otherwise application performance may suffer due to these being shared over NFS back to the host
RUN mkdir -p "/tmp/elinoi/cache" \
    && mkdir -p "/tmp/elinoi/logs" \
    && mkdir -p "/tmp/elinoi/sessions" \
    && chown www-data:www-data -R "/tmp/elinoi"

RUN apt-get update \
    && apt-get -y --no-install-recommends install openssh-server \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN mkdir /var/run/sshd
RUN echo 'root:screencast' | chpasswd
RUN sed -i 's/PermitRootLogin without-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
ADD docker/.ssh /root/.ssh
RUN chmod 700 /root/.ssh/authorized_keys

CMD ["/usr/sbin/sshd", "-D"]

WORKDIR "/var/www/elinoi.com"

并给出错误:

Step 5/19 : RUN gem install ffi --version="1.9.18"
 ---> Running in 35fc010838c3
Building native extensions.  This could take a while...
ERROR:  Error installing ffi:
    ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/ffi-1.9.18/ext/ffi_c
/usr/bin/ruby2.3 -r ./siteconf20180307-7-472r8y.rb extconf.rb
checking for ffi.h... *** 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-ffi_c-dir
    --without-ffi_c-dir
    --with-ffi_c-include
    --without-ffi_c-include=${ffi_c-dir}/include
    --with-ffi_c-lib
    --without-ffi_c-lib=${ffi_c-dir}/lib
    --with-libffi-config
    --without-libffi-config
    --with-pkg-config
    --without-pkg-config
/usr/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/lib/ruby/2.3.0/mkmf.rb:587:in `try_cpp'
    from /usr/lib/ruby/2.3.0/mkmf.rb:1091:in `block in have_header'
    from /usr/lib/ruby/2.3.0/mkmf.rb:942:in `block in checking_for'
    from /usr/lib/ruby/2.3.0/mkmf.rb:350:in `block (2 levels) in postpone'
    from /usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /usr/lib/ruby/2.3.0/mkmf.rb:350:in `block in postpone'
    from /usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /usr/lib/ruby/2.3.0/mkmf.rb:346:in `postpone'
    from /usr/lib/ruby/2.3.0/mkmf.rb:941:in `checking_for'
    from /usr/lib/ruby/2.3.0/mkmf.rb:1090:in `have_header'
    from extconf.rb:16:in `<main>'

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/ffi-1.9.18/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/ffi-1.9.18 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/ffi-1.9.18/gem_make.out
ERROR: Service 'elinoi-php-fpm' failed to build: The command '/bin/sh -c gem install ffi --version="1.9.18"' returned a non-zero code: 1

1 个答案:

答案 0 :(得分:1)

您的图片缺少gcc / g ++编译器,因此无法构建任何本机代码,您可以从错误消息中清楚地看到:

You have to install development tools first.

您可以安装build-essential元数据包,以便在图像中获得有效的构建环境。

RUN apt-get install -y build-essential

当然,在您已经拥有的gem install RUN命令之前,您需要上面一行

相关问题