How to Compile and Statically Link Ruby Libs for Docker

Error loading shared library libsqlite3.so.0 in Docker container

Dynamic libraries or shared objects (files ending in .so) need to be present on the system in order to run the program. Your long RUN command is installing sqlite-libs and using it during the bundle install phase, but then deleting it again; the sqlite gem needs the dynamic library to still be installed.

I'd install this in a separate RUN command. Since the development package is likely to depend on the runtime library, I'd install it first to reduce churn and download time (marginally).

RUN apk add --no-cache sqlite-libs
RUN apk add --no-cache --virtual=.build-deps \
git openssh-client build-base mariadb-dev sqlite-dev \
... \
&& apk del .build-deps

How to install jekyll to a Docker image?

To diagnose the issue you can jump into the container and dig into what's causing the issue.

$ docker run -ti --rm ruby:slim /bin/bash
root@bda37983a585:/# gem install jekyll
# ...

Alternatively there is always the jekyll docker image:
https://hub.docker.com/u/jekyll/

Good luck!

serving static files on sinatra

You can check the settings object.

irb(main):001:0> require "sinatra"
=> true
irb(main):002:0> settings.public_folder
=> "/usr/lib/ruby/2.5.0/irb/public"

This allows you to create a route which returns the path, something like this

require 'sinatra'

get '/' do
settings.public_folder
end

Without more information I would guess that your public folder points to a wrong directory inside your docker because the project :root points to a different directory that what you expect.

Installing gems with native extension on docker image

Your image is missing the gcc/g++ compiler and therefore it can't build any native code, as you can clearly see from the error message:

You have to install development tools first.

You can install the build-essential metapackage to get a working build environment inside your image.

RUN apt-get install -y build-essential

Of course you need the above line before the gem install RUN command you already have



Related Topics



Leave a reply



Submit