How to create a docker image with passenger?

I’m trying to create a docker image with a rails app and passenger.
I have read this article : https://intercityup.com/blog/how-i-build-a-docker-image-for-my-rails-app.html

It works good, gems are well installed, but when I call the app, I have this error :

  • Why does “docker login” fail in Docker Quickstart Terminal but work from within the default machine?
  • docker: extracting a layer from a image
  • How to choose to which network doing port mapping
  • Can I run multiple programs in a Docker container?
  • Docker hiding IP of calling container [closed]
  • How to create docker image for postgis that will enable extension at build time or before container fully running?
  • Message from application: libruby.so.2.1: cannot open shared object file: No such file or directory – /home/app/webapp/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0/pg-0.18.3/pg_ext.so (LoadError)

    And when I’m connecting to the image, the file /home/app/webapp/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0/pg-0.18.3/pg_ext.so really exists.

    So I don’t understand what happened.

    My docker file :

    FROM phusion/passenger-ruby21:0.9.12
    MAINTAINER Eric L'Hostis "eric.lhostis@gmail.com"
    
    # Set correct environment variables.
    ENV HOME /root
    
    # Use baseimage-docker's init system.
    CMD ["/sbin/my_init"]
    
    # Conf Nginx / Passenger
    RUN rm -f /etc/service/nginx/down
    RUN rm /etc/nginx/sites-enabled/default
    ADD nginx.conf /etc/nginx/sites-enabled/webapp.conf
    
    # Prepare folders
    RUN mkdir /home/app/webapp
    WORKDIR /tmp
    ADD Gemfile /tmp/
    ADD Gemfile.lock /tmp/
    RUN bundle install
    
    # Add the rails app
    ADD . /home/app/webapp
    

    And to create/run the image.

    docker build -t myimage .
    docker run -d -p 80:80 myimage
    

    I have already trying to install these libs : libpq-dev, nodejs, build-essential, postgresql
    without success 🙁

  • Docker : find sendmail in other container
  • docker run -i -t image /bin/bash - source files first
  • Appending to base image's ENTRYPOINT
  • Commands in Dockerfile don't seem to be running
  • Docker container for Swagger UI not loading
  • haproxy / docker No enabled listener found (check for 'bind' directives) ! Exiting
  • One Solution collect form web for “How to create a docker image with passenger?”

    My assumption is that you’re using postgres as database and you are missing libpq-dev in your image.

    I don’t use passenger when deploying rails apps with docker, but I think you should check if the lib is installed.

    You could just try to add:

    RUN apt-get install -y libpq-dev 
    

    in your DOCKERFILE to install the lib.

    or even better:

    RUN apt-get update && \
        apt-get install -y libpq-dev --no-install-recommends && \
        rm -rf /var/lib/apt/lists/* && \
        apt-get clean
    

    If you wan’t your image to be as small as possible.

    Side note:

    In my opinion the base image you’re using contains huge overhead. When working with docker my images are usually less than 400 MB. The base image you use is ~960 MB. You should check whether you could use :latest as it’s way smaller (~211 MB).

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