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 :

  • Mount Volume To User's Home Directory In Docker Container
  • COPY doesn't work on Docker prod
  • docker connect from container to public ip of host
  • Jenkins, Docker Build Step create image returns NullPointerException
  • Configuring Docker multi-container App with Spring Cloud Server for OpenShift Origin
  • How to build on host when running Jenkins inside a Docker container?
  • 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 🙁

  • Cannot get image on Docker - Network timed out [Windows]
  • connecting Docker on Windows to Google Cloud Datalab
  • How to detemine the docker entrypoint with snapshot builds?
  • Install MySQL connector/J in Docker container
  • gcloud docker push no space left error
  • Can't access to docker mongo without being root
  • 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.