添加libvips到Rails 7 Docker镜像



我是Docker的新手,并试图为这个新的Rails 7应用程序创建一个Dockerfile。我使用vips而不是imagemagick来获得内存优势。

和我的本地机器是mac所以brew install vips照顾我的非docker开发流程,但它没有那么好使用红宝石vips宝石,或从源代码安装。

运行$ docker compose up结果:

/usr/local/bundle/gems/ffi-1.15.5/lib/ffi/library.rb:145:in block in ffi_lib': Could not open library 'vips.so.42': vips.so.42: cannot open shared object file: No such file or directory. (LoadError)

使用以下docker-compose.yml:

version: "3.9"
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db

和Dockerfile:

FROM ruby:3.0.1
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN gem install ruby-vips
RUN bundle install
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
# Configure the main process to run when running the image
CMD ["rails", "server", "-b", "0.0.0.0"]

我也试过从源代码(https://www.libvips.org/install.html)安装使用ruby-vips没有运气。

;ruby-vips需要libvips42安装在你的docker镜像上。

更新你的Dockerfile以使用以下内容:

RUN apt-get update -qq && apt-get install -y --no-install-recommends nodejs postgresql-client libvips42

PS:运行docker compose downdocker compose up --build强制重建您的docker镜像。

我不认为你实际上在你的dockerfile中安装libvips。试试这个:

FROM ruby:3.0.1
RUN apt-get update -qq 
&& apt-get install -y nodejs postgresql-client
RUN apt install -y --no-install-recommends libvips42
WORKDIR /myapp
...

然而,这将安装与buster附带的libvips,它是8.7。五年前的X (!!)

我将从源代码构建当前libvips。像这样:

# based on buster
FROM ruby:3.0.1
RUN apt-get update && apt-get install -y 
build-essential 
unzip 
wget 
git 
pkg-config
# stuff we need to build our own libvips ... this is a pretty random selection
# of dependencies, you'll want to adjust these
RUN apt-get install -y 
glib-2.0-dev 
libexpat-dev 
librsvg2-dev 
libpng-dev 
libgif-dev 
libjpeg-dev 
libexif-dev 
liblcms2-dev 
liborc-dev
ARG VIPS_VERSION=8.12.2
ARG VIPS_URL=https://github.com/libvips/libvips/releases/download
RUN apt-get install -y 
wget
RUN cd /usr/local/src 
&& wget ${VIPS_URL}/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.gz 
&& tar xzf vips-${VIPS_VERSION}.tar.gz 
&& cd vips-${VIPS_VERSION} 
&& ./configure --disable-deprecated 
&& make -j 4 V=0 
&& make install
RUN gem install ruby-vips

不支持GIF保存,也不支持HEIC或PDF等格式。你可能需要稍微调整一下。当然,你不应该在你的部署docker镜像中构建包,你应该在一个单独的dockerfile中完成。

希望ruby-vip的部署在接下来的几个月里变得更加自动化,因为这是rail7的默认配置。

最新更新