Running Rails application in docker container

I want to run a Rails 4.2.1 application in a docker container on a debian machine.

When I run bundle exec rails s I got this error:

  • Error cannot find -lz building MariaDB on a debian based container
  • GCE persistent disk, kubernetes, and data persistence
  • Discourse run on nginx got 403 forbidden
  • Php development inside docker on ubuntu 16.04 for cpanel shared hosting with some addon domain on it
  • 'docker cp' command in Jenkins docker container copies a file into a directory
  • Mounting a host directory through docker-compose file version “3” and re-using the data-volume
  • Could not find json-1.7.7 in any of the sources
    Run `bundle install` to install missing gems.
    

    When I run bundle install I got this error:

    Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150604-137-10l84fa.                                                                                              rb extconf.rb
    creating Makefile
    
    make "DESTDIR=" clean
    
    make "DESTDIR="
    compiling generator.c
    In file included from generator.c:1:0:
    ../fbuffer/fbuffer.h: In function 'fbuffer_to_s':
    ../fbuffer/fbuffer.h:175:47: error: macro "rb_str_new" requires 2 arguments,    but                                                                                                only 1 given
     VALUE result = rb_str_new(FBUFFER_PAIR(fb));
                                               ^
    ../fbuffer/fbuffer.h:175:20: warning: initialization makes integer from pointer                                                                                             without a cast
     VALUE result = rb_str_new(FBUFFER_PAIR(fb));
                    ^
     Makefile:237: recipe for target 'generator.o' failed
      make: *** [generator.o] Error 1
    
      make failed, exit code 2
    
     Gem files will remain installed in /var/www/test/xyz/vendor/bundle/ruby/2                                                                                              .2.0/gems/json-1.7.7 for inspection.
    Results logged to /var/www/test/xyz/vendor/bundle/ruby/2.2.0/extensions/x                                                                                                86_64-linux/2.2.0/json-1.7.7/gem_make.out
    An error occurred while installing json (1.7.7), and Bundler cannot continue.
    Make sure that `gem install json -v '1.7.7'` succeeds before bundling.
    

    Whats going wrong? what can I do now?

  • How to run a library in docker - confusion
  • How to download file from docker container?
  • Syntaxnet spec file and Docker?
  • Rsync “permission denied” error using Vagrant's docker provider on Windows
  • creating /tmp directory inside docker
  • Accessing Bluetooth dongle from inside Docker?
  • 2 Solutions collect form web for “Running Rails application in docker container”

    docker-rails is a project I just created to make rails with docker (and CI) very easy. I think it can help you and reduce the amount of configuration necessary to get up and running with rails on docker.

    It creates a global shared gem volume (to speed up bundler), and has a sample Dockerfile for use.

    Given that native error, I’m guessing your Dockerfile is missing a needed package, you may need to update your apt-get statements.

    I got the same error. This error is because of the versions of ruby softwares (gems) that we uses doesn’t match at some point.

    You are using ruby version 2.2.1. Your Gemfile contains the gems of older versions and it depends on json version 1.7.7.

    You should install the following ruby version:

    ruby-1.9.3-p448
    

    to get rid of the error, OR updating your gems that compatible with ruby version 2.2.1 will do the trick.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.