title: Docker Build failing when dockerizing rails application
body: <p>I'm dockerizing a rails application, when trying to build the docker image from the docker file which I've written, rails installation is failing.</p>
  <p>This is the Dockerfile. I've made sure the ruby, rails, and bundler versions on my laptop and in the Dockerfile are the same.</p>
  <p>My docker version is <code>Docker version 20.10.5, build 55c4c88</code></p>
  <pre><code>FROM ubuntu:16.04
  
  ENV RUBY_MAJOR=&quot;2.6&quot; \
      RUBY_VERSION=&quot;2.6.3&quot; \
      RUBYGEMS_VERSION=&quot;3.0.8&quot; \
      BUNDLER_VERSION=&quot;1.17.3&quot; \
      RAILS_VERSION=&quot;5.2.1&quot; \
      RAILS_ENV=&quot;production&quot; \
      GEM_HOME=&quot;/usr/local/bundle&quot;
  ENV BUNDLE_PATH=&quot;$GEM_HOME&quot; \
      BUNDLE_BIN=&quot;$GEM_HOME/bin&quot; \
      BUNDLE_SILENCE_ROOT_WARNING=1 \
      BUNDLE_APP_CONFIG=&quot;$GEM_HOME&quot;
  
  ENV PATH=&quot;$BUNDLE_BIN:$GEM_HOME/bin:$GEM_HOME/gems/bin:$PATH&quot;
  
  USER root
  RUN apt-get update &amp;&amp; \
        apt-get -y install sudo
  RUN echo &quot;%sudo ALL=(ALL) NOPASSWD: ALL&quot; &gt;&gt; /etc/sudoers &amp;&amp; \
      addgroup --gid 1024 stars &amp;&amp; \
      useradd -G stars,sudo -d /home/user --shell /bin/bash -m user
  RUN mkdir -p /usr/local/etc \
      &amp;&amp; echo 'install: --no-document' &gt;&gt; /usr/local/etc/gemrc \
      &amp;&amp; echo 'update: --no-document' &gt;&gt; /usr/local/etc/gemrc
  
  USER user
  RUN sudo apt-get -y install --no-install-recommends vim make gcc zlib1g-dev autoconf build-essential libssl-dev libsqlite3-dev \
      curl htop unzip mc openssh-server openssl bison libgdbm-dev ruby git libmysqlclient-dev tzdata mysql-client
      
  RUN sudo rm -rf /var/lib/apt/lists/* \
      &amp;&amp; sudo curl -fSL -o ruby.tar.gz &quot;http://cache.ruby-lang.org/pub/ruby/$RUBY_MAJOR/ruby-$RUBY_VERSION.tar.gz&quot; \
      &amp;&amp; sudo mkdir -p /usr/src/ruby \
      &amp;&amp; sudo tar -xzf ruby.tar.gz -C /usr/src/ruby --strip-components=1 \
      &amp;&amp; sudo rm ruby.tar.gz
  
  USER root
  RUN cd /usr/src/ruby \
      &amp;&amp; { sudo echo '#define ENABLE_PATH_CHECK 0'; echo; cat file.c; } &gt; file.c.new &amp;&amp; mv file.c.new file.c \
      &amp;&amp; autoconf \
      &amp;&amp; ./configure --disable-install-doc
  
  USER user
  RUN cd /usr/src/ruby \
      &amp;&amp; sudo make -j&quot;$(nproc)&quot; \
      &amp;&amp; sudo make install \
      &amp;&amp; sudo gem update --system $RUBYGEMS_VERSION \
      &amp;&amp; sudo rm -r /usr/src/ruby
  RUN sudo gem install bundler --version &quot;$BUNDLER_VERSION&quot;
  
  RUN sudo mkdir -p &quot;$GEM_HOME&quot; &quot;$BUNDLE_BIN&quot; \
      &amp;&amp; sudo chmod 777 &quot;$GEM_HOME&quot; &quot;$BUNDLE_BIN&quot; \
      &amp;&amp; sudo gem install rails --version &quot;$RAILS_VERSION&quot;
  RUN mkdir -p ~/.ssh &amp;&amp; \
      chmod 0700 ~/.ssh &amp;&amp; \
      ssh-keyscan github.com &gt; ~/.ssh/known_hosts
  ARG ssh_pub_key
  ARG ssh_prv_key
  RUN echo &quot;$ssh_pub_key&quot; &gt; ~/.ssh/id_rsa.pub &amp;&amp; \
      echo &quot;$ssh_prv_key&quot; &gt; ~/.ssh/id_rsa &amp;&amp; \
      chmod 600 ~/.ssh/id_rsa.pub &amp;&amp; \
      chmod 600 ~/.ssh/id_rsa
  USER root
  RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
  RUN apt-get install -y nodejs
  USER user
  WORKDIR /data
  RUN sudo mkdir /data/checklist
  WORKDIR /data/checklist
  ADD Gemfile Gemfile.lock ./
  RUN sudo chown -R user /data/checklist
  RUN bundle install
  ADD . .
  RUN sudo chown -R user /data/checklist
  EXPOSE 3001
  ENV RAILS_SERVE_STATIC_FILES true
  ENV RAILS_LOG_TO_STDOUT true
  RUN chmod +x ./config/docker/prepare-db.sh &amp;&amp; sh ./config/docker/prepare-db.sh
  
  CMD [&quot;sh&quot;, &quot;./config/docker/startup.sh&quot;]
  </code></pre>
  <p>Error is</p>
  <pre><code>#13 90.14 ERROR:  Error installing rails:
  #13 90.14   ERROR: Failed to build gem native extension.
  #13 90.14 
  #13 90.14     current directory: /usr/local/lib/ruby/gems/2.6.0/gems/mimemagic-0.3.10/ext/mimemagic
  #13 90.14 /usr/local/bin/ruby -rrubygems /usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/exe/rake RUBYARCHDIR\=/usr/local/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0-static/mimemagic-0.3.10 RUBYLIBDIR\=/usr/local/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0-static/mimemagic-0.3.10
  #13 90.14 rake aborted!
  #13 90.14 Could not find MIME type database in the following locations: [&quot;/usr/local/share/mime/packages/freedesktop.org.xml&quot;, &quot;/opt/homebrew/share/mime/packages/freedesktop.org.xml&quot;, &quot;/opt/local/share/mime/packages/freedesktop.org.xml&quot;, &quot;/usr/share/mime/packages/freedesktop.org.xml&quot;]
  #13 90.14 
  #13 90.14 Ensure you have either installed the shared-mime-info package for your distribution, or
  #13 90.14 obtain a version of freedesktop.org.xml and set FREEDESKTOP_MIME_TYPES_PATH to the location
  #13 90.14 of that file.
  #13 90.14 
  #13 90.14 This gem might be installed as a dependency of some bigger package, such as rails, activestorage,
  #13 90.14 axlsx or cucumber. While most of these packages use the functionality of this gem, some gems have
  #13 90.14 included this gem by accident. Set USE_FREEDESKTOP_PLACEHOLDER=true if you are certain that you
  #13 90.14 do not need this gem, and wish to skip the inclusion of freedesktop.org.xml.
  #13 90.14 
  #13 90.14 The FREEDESKTOP_PLACEHOLDER option is meant as a transitional feature, and will be deprecated in
  #13 90.14 the next release.
  #13 90.14 
  #13 90.14 Tasks: TOP =&gt; default
  #13 90.14 (See full trace by running task with --trace)
  #13 90.14 
  #13 90.14 rake failed, exit code 1
  #13 90.14 
  #13 90.14 Gem files will remain installed in /usr/local/lib/ruby/gems/2.6.0/gems/mimemagic-0.3.10 for inspection.
  #13 90.14 Results logged to /usr/local/lib/ruby/gems/2.6.0/extensions/x86_64-linux/2.6.0-static/mimemagic-0.3.10/gem_make.out
  ------
  executor failed running [/bin/sh -c sudo mkdir -p &quot;$GEM_HOME&quot; &quot;$BUNDLE_BIN&quot;     &amp;&amp; sudo chmod 777 &quot;$GEM_HOME&quot; &quot;$BUNDLE_BIN&quot;     &amp;&amp; sudo gem install rails --version &quot;$RAILS_VERSION&quot;]: exit code: 1
  </code></pre>
  <p>I'm stuck here not able to proceed further. Please help me out.</p>