When trying to insert a specific gem (levenshtein) with Docker, an error occurred without ruby-dev

What I tried to do

I was trying to run a certain Ruby script with Docker. The image of Ruby uses the one in Docker Hub.

Dockerfile

FROM ruby:2.6.3-alpine3.10

RUN gem install bundler \
    && gem install nkf \
    && gem install levenshtein -v 0.2.1

WORKDIR /home/app

Of these

gem install levenshtein

Got running. The following error turned bright red.

Building native extensions. This could take a while...
ERROR:  Error installing levenshtein:
	ERROR: Failed to build gem native extension.

    current directory: /usr/local/bundle/gems/levenshtein-0.2.1/ext/levenshtein
/usr/local/bin/ruby -I /usr/local/lib/ruby/2.6.0 -r ./siteconf20201202-1-c2z6n1.rb extconf.rb
checking for -llevenshtein_array... *** 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/local/bin/$(RUBY_BASE_NAME)
	--with-levenshtein-dir
	--without-levenshtein-dir
	--with-levenshtein-include
	--without-levenshtein-include=${levenshtein-dir}/include
	--with-levenshtein-lib
	--without-levenshtein-lib=${levenshtein-dir}/lib
	--with-levenshtein_arraylib
	--without-levenshtein_arraylib
/usr/local/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:552:in `try_link0'
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:789:in `try_func'
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:1016:in `block in have_library'
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:331:in `open'
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:331:in `open'
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
	from /usr/local/lib/ruby/2.6.0/mkmf.rb:1011:in `have_library'
	from extconf.rb:5:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /usr/local/bundle/extensions/x86_64-linux/2.6.0/levenshtein-0.2.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/bundle/gems/levenshtein-0.2.1 for inspection.
Results logged to /usr/local/bundle/extensions/x86_64-linux/2.6.0/levenshtein-0.2.1/gem_make.out
ERROR: Service 'evaluation_batch' failed to build: The command '/bin/sh -c gem install bundler     && gem install nkf     && gem install levenshtein -v 0.2.1' returned a non-zero code: 1

When I searched based on the following error message,

The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first.

It seems that the cause is that ruby-dev is not included, I added the following to the Dockerfile and rebuilt it. The error has been resolved and the gem-based script now runs on docker.

RUN apk add --no-cache --virtual .build-deps \
    build-base \
    ruby-dev
Step 3/4 : RUN gem install bundler     && gem install nkf     && gem install levenshtein -v 0.2.1
 ---> Running in 4d7c71eeb8b4
Successfully installed bundler-2.1.4
1 gem installed
Successfully installed nkf-0.1.0
1 gem installed
Building native extensions. This could take a while...
Successfully installed levenshtein-0.2.1
1 gem installed
Removing intermediate container 4d7c71eeb8b4
 ---> 77b3497a07a7
Step 4/4 : WORKDIR /home/app
 ---> Running in 0b885a656f8c
Removing intermediate container 0b885a656f8c
 ---> 2dbafbc33e73

Helpful site

https://www.aska-ltd.jp/en/blog/60 https://www.xmisao.com/2014/07/06/cannot-load-such-file-mkmf.html

Recommended Posts

When trying to insert a specific gem (levenshtein) with Docker, an error occurred without ruby-dev
[Error resolution] Occurs when trying to build an environment for spring with docker
An error occurred when executing a function from MyBatis with the OUT parameter set to CURSOR in PostgreSQL.
When introducing JOOQ to Spring boot, a story that was dealt with because an error occurred around Liquibase
When I bcrypt with node + docker, I got an error
I got an error when trying to install sbt to build a Scala development environment
About the solution of the error that occurred when trying to create a Japanese file of devise in the Docker development environment
A validation error occurred when saving to the intermediate table.
I was angry with proc_open (): fork failed when trying to composer update inside a Docker container
I got an IllegalAccessError when trying to use PowerMock with JUnit
Resolved the error that occurred when trying to use Spark in an environment where Java 8 and Java 11 coexist.
[Unauthorized Operation] A memorandum because an error occurred when creating an EC2 instance.
When registering a new user, I got an error called ActiveRecord :: NotNullViolation and how to deal with it.
Error when trying to use heroku command
A reminder when an aapt.exe error occurs
Error response from daemon: conflict: Conflict when trying to create Docker container, so solution
Solution that gives an error when trying to connect to DB (MySQL) in Java
[Laravel] How to deal with out of memory error when composer require [Docker]
A memorandum when building an environment with Ruby3.0 x Rails6.1 x Docker x CentOS Stream
Summary when trying to use Solr in Java and getting an error (Solr 6.x)
407 error when trying to access an HTTPS site in Java via an authenticated proxy
NoClassDefFoundError occurred when trying to call an Android function from Unity via jar
What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field
Webdrivers :: BrowserNotFound: Failed to find Chrome binary. When I was trying to test E2E with Docker + Rails for the first time, I got stuck in an error.
I get an error when adding a dependency
When deploying to Heroku, OpenApp causes an error
[Rails] How to build an environment with Docker
After installing'devise''bootstrap' of gemfile with rails, what to do when url is an error
A story that got stuck with an error during migration in docker PHP laravel
A story about PKIX path building failed when trying to deploy to tomcat with Jenkins
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
Docker command to create Rails project with a single blow in environment without Ruby
A warning is displayed when trying to use a huge integer with the special variables $ 1, $ 2, $ 3 ...