title: Rails build is failing using Docker. Nokogiri is causing the error when I use ruby:alpine image
body: <p>I have a bare bone Rails 5.x that I am trying to get working using docker.</p>
  
  <p>I am using google cloud build to build my image.  When I perform the docker build on Ubuntu 18.x it works fine.</p>
  
  <p>My Dockerfile looks like this:</p>
  
  <pre><code>FROM ruby:2.5-alpine
  
  RUN apk update &amp;&amp; apk --update add \
   build-base \
   nodejs \
   postgresql-dev \
   tzdata \
   imagemagick 
  
  #RUN apt-get install -y build-essential
  
  # yarn
  ENV PATH=/root/.yarn/bin:$PATH
  RUN apk add --virtual build-yarn curl &amp;&amp; \
      touch ~/.bashrc &amp;&amp; \
      curl -o- -L https://yarnpkg.com/install.sh | sh &amp;&amp; \
      apk del build-yarn
  
  
  RUN mkdir /app
  WORKDIR /app
  
  COPY Gemfile ./
  RUN gem install bundler -v 2.0.1
  RUN gem uninstall bundler --version '&lt;2.0.0'
  RUN gem install nokogiri -v '1.10.1' --source 'https://rubygems.org/'
  RUN bundle install --binstubs
  </code></pre>
  
  <p>When I am building my Docker image I get this error:</p>
  
  <pre><code>Successfully installed mini_portile2-2.4.0 Building native extensions.
  This could take a while... ERROR:  Error installing nokogiri:   ERROR:
  Failed to build gem native extension.
  
      current directory: /usr/local/bundle/gems/nokogiri-1.10.1/ext/nokogiri
  /usr/local/bin/ruby -I /usr/local/lib/ruby/site_ruby/2.5.0 -r
  ./siteconf20190303-1-7m260v.rb extconf.rb checking if the C compiler
  accepts ... *** 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)     --help  --clean
  /usr/local/lib/ruby/2.5.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/local/lib/ruby/2.5.0/mkmf.rb:574:in `block in try_compile'     from
  /usr/local/lib/ruby/2.5.0/mkmf.rb:521:in `with_werror'  from
  /usr/local/lib/ruby/2.5.0/mkmf.rb:574:in `try_compile'  from
  extconf.rb:138:in `nokogiri_try_compile'    from extconf.rb:162:in
  `block in add_cflags'   from /usr/local/lib/ruby/2.5.0/mkmf.rb:632:in
  `with_cflags'   from extconf.rb:161:in `add_cflags'     from
  extconf.rb:416:in `&lt;main&gt;'
  
  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.5.0/nokogiri-1.10.1/mkmf.log
  
  extconf failed, exit code 1
  
  Gem files will remain installed in
  /usr/local/bundle/gems/nokogiri-1.10.1 for inspection. Results logged
  to
  /usr/local/bundle/extensions/x86_64-linux/2.5.0/nokogiri-1.10.1/gem_make.out
  The command '/bin/sh -c gem install nokogiri -v '1.10.1' --source
  'https://rubygems.org/'' returned a non-zero code: 1 ERROR ERROR:
  build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1
  </code></pre>
  
  <p>Do I need to use another image type that supports build-essential?
  Is there another way around installing nokogiri?</p>
  
  <p>I'm confused, is the issue with the Dockerfile or the environment that is building the docker image i.e. google cloud build?</p>